PhoneGap iPhone app crashing when push notificatio

2019-09-13 18:20发布

问题:

Xcode 4.2, using PhoneGap template, Urban Airship library.

Xcode compiles my application and installs it on my iPhone, and I can send push notifications to it from the Urban Airship Web interface.

So here’s my problem: If I tap on a notification while the app is open in the background, the app comes into the foreground. However, if the app is not already in the background when I tap a notification, the app intro screen briefly appears, and the app immediately crashes.

At this point, the app is now in the background, and I can open it and operate it.

I have downloaded and installed the Library and Sample App from http://urbanairship.com/docs/apns_test_client.html and have gotten it to work correctly on my iPhone: I can receive notifications from Urban Airship, and the app opens when I tap a notification, even though the app wasn’t already in the background. Of course, this sample doesn’t use PhoneGap.

I’m hoping maybe someone else, has experienced this problem, or can at least recognize the symptoms, and has an idea what I might do to fix it.

回答1:

This is a small bug in phonegap.

in your AppDelegate.m file look at didFinishLaunchingWithOptions, if you comment out the lines below that problem should go away.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    //commented out because it makes the app crash at startup with local notification...
    /*NSArray *keyArray = [launchOptions allKeys];
    if ([launchOptions objectForKey:[keyArray objectAtIndex:0]]!=nil) 
    {
        NSURL *url = [launchOptions objectForKey:[keyArray objectAtIndex:0]];
        self.invokeString = [url absoluteString];
        NSLog(@"Mosa_fr_en-busi launchOptions = %@",url);
    }*/

    return [super application:application didFinishLaunchingWithOptions:launchOptions];
}