Last active
August 29, 2015 14:27
-
-
Save helsont/7911f3e0a7c0452b7edc to your computer and use it in GitHub Desktop.
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
- (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; | |
} | |
} |
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
- (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