Skip to content

Instantly share code, notes, and snippets.

@helsont
Last active August 29, 2015 14:27
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 helsont/7911f3e0a7c0452b7edc to your computer and use it in GitHub Desktop.
Save helsont/7911f3e0a7c0452b7edc to your computer and use it in GitHub Desktop.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
NSLog(@"didReceiveNotification");
// Get application state for iOS4.x+ devices, otherwise assume active
UIApplicationState appState = UIApplicationStateActive;
if ([application respondsToSelector:@selector(applicationState)]) {
appState = application.applicationState;
}
if (appState == UIApplicationStateActive) {
PushPlugin *pushHandler = [self getCommandInstance:@"PushPlugin"];
pushHandler.notificationMessage = userInfo;
pushHandler.isInline = YES;
[pushHandler notificationReceived];
} else {
//save it for later
self.launchNotification = userInfo;
}
}
- (void)notificationReceived {
NSLog(@"Notification received");
if (notificationMessage && self.callback)
{
NSMutableDictionary *dict = [notificationMessage mutableCopy];
if (isInline)
{
[dict setValue:@"1" forKey:@"foreground"];
isInline = NO;
}
else {
[dict setValue:@"0" forKey:@"foreground"];
}
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:0 error:&error];
NSString *jsonString;
if (!jsonData) {
NSLog(@"JSON error:%@", error);
} else {
jsonString = [[NSString alloc] initWithBytes:[jsonData bytes] length:[jsonData length] encoding:NSUTF8StringEncoding];
NSLog(@"JSON OUTPUT: %@", jsonString);
}
NSString * jsCallBack = [NSString stringWithFormat:@"%@(%@);", self.callback, jsonString];
[self.webView stringByEvaluatingJavaScriptFromString:jsCallBack];
self.notificationMessage = nil;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment