For when wanting to get the information of the push notification in your app, for example to display a message
I'm not implementing pull request because I know that the way I hacked the notificationRecived probably can be made better. I have zero knowledge on C#
in appDelegate.m --> - (BOOL)application:(UIApplication_)application didFinishLaunchingWithOptions:(NSDictionary_)launchOptions
if (launchOptions != nil)
{
NSDictionary* dictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
NSLog(@"Launched from push notification: %@" , dictionary);
if (dictionary != nil)
{
// get the necessary information out of the dictionary
// (the data you sent with your push message)
// and load your data
PushPlugin *pushHandler = [self.viewController getCommandInstance:@"PushPlugin"];
pushHandler.notificationMessage = dictionary;
pushHandler.isInline = YES;
[pushHandler notificationReceived];
}
}
This will call the plugin.
PushPlugin.m --> - (void)notificationReceived
- (void)notificationReceived {
if (notificationMessage) {
NSString *exists = [self.webView stringByEvaluatingJavaScriptFromString:@"isLoaded()"];
NSString *MyTrue = @"true";
if ([MyTrue isEqualToString:exists]) {
NSLog(@"Notification received isNotLoading");
NSMutableString *jsonStr = [NSMutableString stringWithString:@"{"];
[self parseDictionary:notificationMessage intoJSON:jsonStr];
if (isInline) {
[jsonStr appendFormat:@"foreground:'%d',", 1];
isInline = NO;
}
[jsonStr appendString:@"}"];
NSLog(@"Msg: %@", jsonStr);
NSString * jsCallBack = [NSString stringWithFormat:@"%@(%@);", self.callback, jsonStr];
[self.webView stringByEvaluatingJavaScriptFromString:jsCallBack];
self.notificationMessage = nil;
} else {
NSLog(@"Notification received isLoading");
[NSTimer scheduledTimerWithTimeInterval: 5 target: self selector: @selector(notificationReceived) userInfo: nil repeats: NO];
}
}
}
I try to see if the webview is available, if not I loop, if someone has a better idea please do tell!
In my javascript
var loaded = "false";
function isLoaded () {
return loaded;
}
$(document).ready(function () {
loaded = "true";
});
I use $(document).ready because I use jquery and I want to check that jquery is working!
Hope this helps someone!