Last active
August 29, 2015 14:11
-
-
Save tayl0r/64d63e90b758036f9771 to your computer and use it in GitHub Desktop.
notif tracking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "PluginBase/AppDelegateListener.h" | |
+ (void)load | |
{ | |
// startup notification (local and remote) | |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(FoxCubIosOnLoad:) name:UIApplicationDidFinishLaunchingNotification object:nil]; | |
// resume notification (local) | |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(FoxCubIosOnLocalNotif:) name:kUnityDidReceiveLocalNotification object:nil]; | |
// resume notification (remote) | |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(FoxCubIosOnRemoteNotif:) name:kUnityDidReceiveRemoteNotification object:nil]; | |
} | |
+ (void)FoxCubIosOnRemoteNotif:(NSNotification*) notification | |
{ | |
id dict = [notification userInfo]; | |
NSDictionary* remote = dict; | |
if (remote == nil) { | |
NSLog(@"FoxCubIosOnRemoteNotif: remote is null"); | |
return; | |
} | |
[self SetLaunchOptions:[remote description]]; | |
} | |
+ (void)FoxCubIosOnLocalNotif:(NSNotification*) notification | |
{ | |
id dict = [notification userInfo]; | |
UILocalNotification* local = dict; | |
if (local == nil) { | |
NSLog(@"FoxCubIosOnLocalNotif: local is null"); | |
return; | |
} | |
NSLog(@"applicationState: %ld", (long)[UIApplication sharedApplication].applicationState); | |
if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) { | |
[self SetLaunchOptions:local.alertBody]; | |
} | |
} | |
+ (void)FoxCubIosOnLoad:(NSNotification*) notification | |
{ | |
NSDictionary* launchOptions = [notification userInfo]; | |
if (launchOptions == nil) { | |
NSLog(@"FoxCubIos: launch options are null"); | |
return; | |
} | |
NSURL* url = [launchOptions valueForKey:UIApplicationLaunchOptionsURLKey]; | |
if (url != nil) { | |
// handle URL | |
NSString* options = url.absoluteString; | |
if (options != nil && options.length > 0) { | |
[self SetLaunchOptions:options]; | |
} else { | |
NSLog(@"FoxCubIos: got url but it is broken"); | |
} | |
} else { | |
NSDictionary* remoteNotif = [launchOptions valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; | |
if (remoteNotif != nil) { | |
[self SetLaunchOptions:[remoteNotif description]]; | |
} else { | |
UILocalNotification* localNotif = [launchOptions valueForKey:UIApplicationLaunchOptionsLocalNotificationKey]; | |
if (localNotif != nil) { | |
[self SetLaunchOptions:localNotif.alertBody]; | |
} else { | |
NSLog(@"FoxCubIos: userInfo does not contain any launch options data."); | |
} | |
} | |
} | |
} | |
+ (void)SetLaunchOptions:(NSString*) options { | |
if (_options != nil) { | |
[_options release]; | |
} | |
_options = [options retain]; | |
NSLog(@"FoxCubIos: got launch options"); | |
NSLog(_options); | |
} | |
@end | |
// C functions to access your plugin from Unity script. | |
// Helper method to create C string copy | |
char* FcMakeStringCopy(const char* string) | |
{ | |
if (string == NULL) | |
return NULL; | |
char* res = (char*)malloc(strlen(string) + 1); | |
strcpy(res, string); | |
return res; | |
} | |
extern "C" const char* FcGetLaunchOptions() | |
{ | |
if (_options == nil) { | |
return NULL; | |
} | |
// By default mono string marshaler creates .Net string for returned UTF-8 C string | |
// and calls free for returned value, thus returned strings should be allocated on heap | |
char* rv = FcMakeStringCopy([_options UTF8String]); | |
_options = nil; | |
return rv; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment