PhoneGap / iOS LocalNotification 应用程序在点击“查看”时崩溃

发布于 2024-11-27 12:07:01 字数 2949 浏览 0 评论 0原文

我在这里遇到了麻烦:我将应用程序设置为不在后台运行,并且我正在使用我在 github 上找到的 localNotification 插件设置 dailyInterval 本地通知: https://github.com/phonegap/phonegap-plugins/tree/master/iPhone/LocalNotification

应用程序崩溃时弹出通知,然后我点击“查看”...看起来有东西正在发送,但它不知道发生了什么。我也不知道发生了什么,因为 Objective C 对我来说是一门外语。有人有什么想法吗?

--------- Console Log ----------

2011 年 7 月 29 日上午 11:05:48 下午确认 [12004] -[UIConcreteLocalNotification AbsoluteString]:无法识别的选择器发送到实例 0x5c22240

7/29/11 11:05:48 AM Afternoon Affirmations[12004]   *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIConcreteLocalNotification absoluteString]: unrecognized selector sent to instance 0x5c22240'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x017f65a9 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x0194a313 objc_exception_throw + 44
    2   CoreFoundation                      0x017f80bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
    3   CoreFoundation                      0x01767966 ___forwarding___ + 966
    4   CoreFoundation                      0x01767522 _CF_forwarding_prep_0 + 50
    5   Afternoon Affirmations              0x00002f21 -[AppDelegate application:didFinishLaunchingWithOptions:] + 257
    6   UIKit                               0x002f7c89 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1163
    7   UIKit                               0x002f9d88 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 439
    8   UIKit                               0x00304617 -[UIApplication handleEvent:withNewEvent:] + 1533
    9   UIKit                               0x002fcabf -[UIApplication sendEvent:] + 71
    10  UIKit                               0x00301f2e _UIApplicationHandleEvent + 7576
    11  GraphicsServices                    0x020e5992 PurpleEventCallback + 1550
    12  CoreFoundation                      0x017d7944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
    13  CoreFoundation                      0x01737cf7 __CFRunLoopDoSource1 + 215
    14  CoreFoundation                      0x01734f83 __CFRunLoopRun + 979
    15  CoreFoundation                      0x01734840 CFRunLoopRunSpecific + 208
    16  CoreFoundation                      0x01734761 CFRunLoopRunInMode + 97
    17  UIKit                               0x002f97d2 -[UIApplication _run] + 623
    18  UIKit                               0x00305c93 UIApplicationMain + 1160
    19  Afternoon Affirmations              0x00002d7f main + 127
    20  Afternoon Affirmations              0x00002cf5 start + 53
)

7/29/11 11:05:48 AM UIKitApplication:com.InTheRooms.AfternoonAffirmations[0x9a52][12004]    terminate called after throwing an instance of 'NSException'

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 github here: https://github.com/phonegap/phonegap-plugins/tree/master/iPhone/LocalNotification

The app crashes when the notification pops up, and I tap "View"... looks like something is being sent along and it doesn't know what's going on. I, also don't know what's going on since Objective C is a foreign language to me. Anyone have any ideas?

--------- Console Log ----------

7/29/11 11:05:48 AM Afternoon Affirmations[12004] -[UIConcreteLocalNotification absoluteString]: unrecognized selector sent to instance 0x5c22240

7/29/11 11:05:48 AM Afternoon Affirmations[12004]   *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIConcreteLocalNotification absoluteString]: unrecognized selector sent to instance 0x5c22240'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x017f65a9 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x0194a313 objc_exception_throw + 44
    2   CoreFoundation                      0x017f80bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
    3   CoreFoundation                      0x01767966 ___forwarding___ + 966
    4   CoreFoundation                      0x01767522 _CF_forwarding_prep_0 + 50
    5   Afternoon Affirmations              0x00002f21 -[AppDelegate application:didFinishLaunchingWithOptions:] + 257
    6   UIKit                               0x002f7c89 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1163
    7   UIKit                               0x002f9d88 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 439
    8   UIKit                               0x00304617 -[UIApplication handleEvent:withNewEvent:] + 1533
    9   UIKit                               0x002fcabf -[UIApplication sendEvent:] + 71
    10  UIKit                               0x00301f2e _UIApplicationHandleEvent + 7576
    11  GraphicsServices                    0x020e5992 PurpleEventCallback + 1550
    12  CoreFoundation                      0x017d7944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
    13  CoreFoundation                      0x01737cf7 __CFRunLoopDoSource1 + 215
    14  CoreFoundation                      0x01734f83 __CFRunLoopRun + 979
    15  CoreFoundation                      0x01734840 CFRunLoopRunSpecific + 208
    16  CoreFoundation                      0x01734761 CFRunLoopRunInMode + 97
    17  UIKit                               0x002f97d2 -[UIApplication _run] + 623
    18  UIKit                               0x00305c93 UIApplicationMain + 1160
    19  Afternoon Affirmations              0x00002d7f main + 127
    20  Afternoon Affirmations              0x00002cf5 start + 53
)

7/29/11 11:05:48 AM UIKitApplication:com.InTheRooms.AfternoonAffirmations[0x9a52][12004]    terminate called after throwing an instance of 'NSException'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

反差帅 2024-12-04 12:07:01

好的,我发现了问题,它在文件 AppDelegate.m 中,更准确地说在方法中:didFinishLaunchingWithOptions。该方法假设第一个选项参数是一个 url(但当我们通过本地通知启动应用程序时,它不是。快速而肮脏的修复方法是注释代码:

- (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];
}

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];
}
我要还你自由 2024-12-04 12:07:01

如果有人感兴趣的话,我已经重写了 localNotification 插件 - 您现在可以添加回调和声音。我喜欢这个问题的解决方案,因为我也遇到过同样的事情。我也将它包含在 GIT 项目中。

吉特项目
https://github.com/DrewDahlman/Phonegap-LocalNotification

和一篇解释更改的博文
http://www.drewdahlman.com/meusLabs/?p=117

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

独自←快乐 2024-12-04 12:07:01

更好一点的解决方案是这样的:

- (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];
}

如果有人知道 PhoneGap 期望 URL 的密钥是什么,最好将 [keyArray objectAtIndex:0] 部分替换为实际密钥。

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.

往日情怀 2024-12-04 12:07:01

我对本地通知也有类似的问题。我选择的解决方案有点不同(尽管非常相似)。我正在使用检查本地通知启动选项(UIApplicationLaunchOptionsLocalNotificationKey)。

这是一个简短的示例:

- (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 文档:
http://developer.apple.com/library/mac/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/IPhoneOSClientImp/IPhoneOSClientImp.html

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文