0

最近、ローカル通知を含むクライアント用のアプリを作成しました。元のバージョンでは、通知はまったく問題なく機能していました。しかし、クライアントが別のバージョンをリリースしようとしたときに、コードを変更せずにイメージと DB リソースのみを変更すると、通知が機能しなくなりました。現在、コードをデバッグしようとしていますが、何も見つかりませんでした。すべて問題ないようですが、通知はありません。一方、以前のビルドを実行すると、完全に機能します。何が問題なのか教えてください。ありがとうございました。

NSTimeInterval diffTimeIntervalSinceNow = timeInterval; //time-interval after which notification should appear


    UILocalNotification *localNotification = [[UILocalNotification alloc] init]; //Create the localNotification object
    [localNotification setFireDate:[NSDate dateWithTimeIntervalSinceNow:diffTimeIntervalSinceNow]]; //Set the date when the alert will be launched using the date adding the time the user selected on the timer
    //[localNotification setRepeatInterval:notificationInterval];

    [localNotification setAlertAction:@"Launch"]; //The button's text that launches the application and is shown in the alert
    [localNotification setAlertBody:alertBody]; //Set the message in the notification from the textField's text
    [localNotification setHasAction: YES]; //Set that pushing the button will launch the application
    [localNotification setApplicationIconBadgeNumber:[[UIApplication sharedApplication] applicationIconBadgeNumber]+1]; //Set the Application Icon Badge Number of the application's icon to the current Application Icon Badge Number plus 1

    [[UIApplication sharedApplication] cancelAllLocalNotifications];
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; //Schedule the notification with the system
    [localNotification release];

それが私が使ってきたコードです。しかし、これは以前のバージョンで動作していたコードとまったく同じです。

4

2 に答える 2

0

クライアントも alertBody を変更し、新しい alertBody の長さが長すぎる可能性がありますか?

于 2012-08-22T07:25:13.583 に答える
0

私はあなたのコードを修正しました:-これを試してください:-ボタンアクションまたは任意のメソッドの内部

  [[UIApplication sharedApplication] cancelAllLocalNotifications];
       NSTimeInterval diffTimeIntervalSinceNow = timeInterval; //time-interval after which notification should appear


            UILocalNotification *localNotification = [[UILocalNotification alloc] init]; //Create the localNotification object
            [localNotification setFireDate:[NSDate dateWithTimeIntervalSinceNow:diffTimeIntervalSinceNow]]; //Set the date when the alert will be launched using the date adding the time the user selected on the timer
            //[localNotification setRepeatInterval:notificationInterval];

            [localNotification setAlertAction:@"Launch"]; //The button's text that launches the application and is shown in the alert
            [localNotification setAlertBody:alertBody]; //Set the message in the notification from the textField's text
            [localNotification setHasAction: YES]; //Set that pushing the button will launch the application
            [localNotification setApplicationIconBadgeNumber:[[UIApplication sharedApplication] applicationIconBadgeNumber]+1]; //Set the Application Icon Badge Number of the application's icon to the current Application Icon Badge Number plus 1


            [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; //Schedule the notification with the system
            [localNotification release];

この作業のために:- アプリデリゲートでこのメソッドをチェックして、何らかのイベントを取得するかどうかを確認します

-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{

}

すべての通知をキャンセルするには、これを使用します

于 2012-05-26T10:58:43.280 に答える