Skip to content

Instantly share code, notes, and snippets.

@RomanovX
Created June 12, 2017 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RomanovX/e8a49766fa935bff40bb6a7d20f75e80 to your computer and use it in GitHub Desktop.
Save RomanovX/e8a49766fa935bff40bb6a7d20f75e80 to your computer and use it in GitHub Desktop.
NativeDataPlugin.m Used as plugin for cordova. We use the init and setEnabledButtonsCall to set the buttons
#import "NativeDataPlugin.h"
#import <Cordova/CDVPluginResult.h>
@implementation NativeDataPlugin
- (void)init : (CDVInvokedUrlCommand *)command
{
NSString * baseUrl = [command argumentAtIndex:0];
NSString * token = [command argumentAtIndex:1];
NSString * phoneDeviceId = [command argumentAtIndex:2];
NSString * callbackId = command.callbackId;
CDVPluginResult * pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult : pluginResult callbackId : callbackId];
NSString * groupPrefix = @"group.";
NSString * bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
NSString * groupIdentifier = [groupPrefix stringByAppendingString:bundleIdentifier];
NSUserDefaults *sharedData = [[NSUserDefaults alloc] initWithSuiteName: groupIdentifier];
[sharedData setObject:baseUrl forKey:@"baseUrl"];
[sharedData setObject:token forKey:@"token"];
[sharedData setObject:phoneDeviceId forKey:@"phoneDeviceId"];
[sharedData synchronize];
NSLog(@"Data initialized. \nServer baseURL: \n%@, \ntoken: \n%@,\nuuid: \n%@", baseUrl, token, phoneDeviceId);
}
- (void)setEnabledButtonsCall : (CDVInvokedUrlCommand *)command
{
NSArray * buttons = command.arguments;
NSString * callbackId = command.callbackId;
CDVPluginResult * pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult : pluginResult callbackId : callbackId];
NSString * groupPrefix = @"group.";
NSString * bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
NSString * groupIdentifier = [groupPrefix stringByAppendingString:bundleIdentifier];
NSUserDefaults *sharedData = [[NSUserDefaults alloc] initWithSuiteName: groupIdentifier];
[sharedData setObject:buttons forKey:@"buttons"];
[sharedData synchronize];
NSLog(@"%@", buttons);
}
- (void)clearData : (CDVInvokedUrlCommand *)command
{
NSString * callbackId = command.callbackId;
CDVPluginResult * pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult : pluginResult callbackId : callbackId];
NSString * groupPrefix = @"group.";
NSString * bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
NSString * groupIdentifier = [groupPrefix stringByAppendingString:bundleIdentifier];
NSUserDefaults *sharedData = [[NSUserDefaults alloc] initWithSuiteName: groupIdentifier];
[sharedData removeObjectForKey:@"buttons"];
[sharedData removeObjectForKey:@"baseUrl"];
[sharedData removeObjectForKey:@"token"];
[sharedData removeObjectForKey:@"phoneDeviceId"];
[sharedData synchronize];
NSLog(@"Cleared app group data for buttons");
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment