Skip to content

Instantly share code, notes, and snippets.

@zbyhoo
Created January 20, 2021 21:26
Show Gist options
  • Save zbyhoo/7a9c8bfa64d1ecb7f6383ee8b179caf8 to your computer and use it in GitHub Desktop.
Save zbyhoo/7a9c8bfa64d1ecb7f6383ee8b179caf8 to your computer and use it in GitHub Desktop.
#import "UnityAppController.h"
@interface MyGameAppController : UnityAppController
@property (class, nonatomic, assign, readonly) NSString* launchNotificationId;
@end
IMPL_APP_CONTROLLER_SUBCLASS(MyGameAppController)
@implementation MyGameAppController
static NSString* _launchNotificationId;
+ (NSString*) launchNotificationId
{
return _launchNotificationId;
}
- (BOOL)application:(UIApplication*)application willFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
if (launchOptions == nil)
{
NSLog(@"launchOptions is nil");
}
else
{
UILocalNotification* notification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
NSDictionary* remoteNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (notification != nil)
{
_launchNotificationId = [NSString stringWithString:notification.alertTitle];
NSLog(@"LAUNCHED WITH LOCAL NOTIFICATION: %@", notification.alertTitle);
}
else if (remoteNotification != nil)
{
NSDictionary* aps = [remoteNotification objectForKey:@"aps"];
if (aps != nil)
{
NSDictionary* alert = [aps objectForKey:@"alert"];
if (alert != nil)
{
NSString* title = [alert objectForKey:@"title"];
_launchNotificationId = [NSString stringWithString:title];
}
}
if (_launchNotificationId != nil)
{
NSLog(@"LAUNCHED WITH REMOTE NOTIFICATION: %@", _launchNotificationId);
}
}
}
return [super application:application willFinishLaunchingWithOptions:launchOptions];
}
@end
extern "C" const char * getAppLaunchNotificationId()
{
NSString* launchNotificationId = [MyGameAppController launchNotificationId];
if (launchNotificationId == nil)
{
return NULL;
}
const char* string = [launchNotificationId UTF8String];
char* res = (char*)malloc(strlen(string) + 1);
strcpy(res, string);
return res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment