PhoneGap / iOS LocalNotification App Crashes on tapping “View”

后端 未结 4 390
孤城傲影
孤城傲影 2021-01-02 20:46

I\'m having trouble here: I have the app set to not run in the background, and I\'m setting a dailyInterval localnotification using a localNotification plugin I found on git

相关标签:
4条回答
  • 2021-01-02 21:25

    I had a similar issue with local notifications. The solution that I chose is a bit different (though quite similar). I'm using a check for a local notification launch option (UIApplicationLaunchOptionsLocalNotificationKey).

    Here is a short example:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        UILocalNotification *localNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
    
        if( localNotif ) 
        {
            // Do whatever you need to do with that local notitication
        }
        else
        {
            NSArray *keyArray = [launchOptions allKeys];
            if ([launchOptions objectForKey:[keyArray objectAtIndex:0]]!=nil) 
            {
                NSURL *url = [launchOptions objectForKey:[keyArray objectAtIndex:0]];
                self.invokeString = [url absoluteString];
            }
        }
        return [super application:application didFinishLaunchingWithOptions:launchOptions];
    }
    

    Apple Docs: http://developer.apple.com/library/mac/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/IPhoneOSClientImp/IPhoneOSClientImp.html

    0 讨论(0)
  • 2021-01-02 21:26

    OK, I found the problem, it's in the file AppDelegate.m and more precisely in the method : didFinishLaunchingWithOptions. The method assumes that the first option parameters is an url (but it's not when we launch the app via a Local Notification. The quick and dirty fix is to comment the code :

    - (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];
    }
    
    0 讨论(0)
  • 2021-01-02 21:36

    I've re-writen the localNotification plugin if anyone is interested - you can now add callbacks as well as sound. I like this fix for this problem as I have faced the same thing. I've also included it in the GIT project.

    the GIT project https://github.com/DrewDahlman/Phonegap-LocalNotification

    and a blog post explaining changes http://www.drewdahlman.com/meusLabs/?p=117

    0 讨论(0)
  • 2021-01-02 21:39

    A little bit better solution is something like this:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        NSArray *keyArray = [launchOptions allKeys];
        if ([keyArray count] > 0) {
            id option = [launchOptions objectForKey:[keyArray objectAtIndex:0]];
            if ([option isKindOfClass:[NSURL class]]) {
                NSURL *url = (NSURL *)option;
                self.invokeString = [url absoluteString];
                NSLog(@"ContactInbox launchOptions = %@",url);
            }
        }
    
        return [super application:application didFinishLaunchingWithOptions:launchOptions];
    }
    

    If somebody knows what key PhoneGap expects to have for URL it's better to replace [keyArray objectAtIndex:0] part with actual key.

    0 讨论(0)
提交回复
热议问题