6

ここで問題が発生しています:アプリをバックグラウンドで実行しないように設定しており、github で見つけた localNotification プラグインを使用して、dailyInterval localnotification を設定しています: https://github.com/phonegap/phonegap-plugins /ツリー/マスター/iPhone/LocalNotification

通知が表示されたときにアプリがクラッシュするので、[表示] をタップします...何かが送信されているようで、何が起こっているのかわかりません。私も、Objective C は私にとって外国語なので、何が起こっているのかわかりません。誰にもアイデアはありますか?

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

7/29/11 11:05:48 AM Afternoon Affirmations[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'
4

4 に答える 4

3

OK、問題が見つかりました。それはファイル 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];
}
于 2011-12-13T20:08:03.510 に答える
2

誰かが興味を持っている場合は、localNotification プラグインを書き直しました。コールバックとサウンドを追加できるようになりました。同じことに直面したので、この問題に対するこの修正が気に入​​っています。GIT プロジェクトにも含めました。

GIT プロジェクト https://github.com/DrewDahlman/Phonegap-LocalNotification

および変更を説明するブログ投稿 http://www.drewdahlman.com/meusLabs/?p=117

于 2012-01-28T16:58:09.547 に答える
0

ローカル通知でも同様の問題がありました。私が選んだ解決策は少し異なります (かなり似ていますが)。ローカル通知起動オプション (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

于 2012-01-28T04:03:12.567 に答える
0

少し良い解決策は次のようなものです。

- (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]その部分を実際のキーに置き換えることをお勧めします。

于 2011-12-27T21:44:11.843 に答える