Skip to content

Instantly share code, notes, and snippets.

@jsoma
Created April 13, 2012 00:06
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 jsoma/2372039 to your computer and use it in GitHub Desktop.
Save jsoma/2372039 to your computer and use it in GitHub Desktop.
LocalNotification Cordova callback fix
// When upgrading the LocalNotification plugin from PhoneGap to Cordova, you run
// into the error "Request for member 'webView' in something not a structure or union"
// from the LLVM GCC 4.2 compiler.
//
// The wonderful callback support is to blame!
//
// You just need to edit AppDelegate.m and replace all instances of this.webView
// with this.viewController.webView and you'll be good to go!
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateInactive) {
// WAS IN BG
NSLog(@"I was in the background");
NSString *notCB = [notification.userInfo objectForKey:@"background"];
NSString * jsCallBack = [NSString
stringWithFormat:@"%@", notCB];
[self.viewController.webView stringByEvaluatingJavaScriptFromString:jsCallBack];
application.applicationIconBadgeNumber = 0;
}
else {
// WAS RUNNING
NSLog(@"I was currently active");
NSString *notCB = [notification.userInfo objectForKey:@"forground"];
NSString * jsCallBack = [NSString
stringWithFormat:@"%@", notCB];
[self.viewController.webView stringByEvaluatingJavaScriptFromString:jsCallBack];
application.applicationIconBadgeNumber = 0;
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment