18

App Store にローカル通知機能を備えたアプリがあります。

私のアプリの過去 4 回のバージョン アップデートで、異常な事態を経験した顧客がいました。アプリが以前の通知を制御できなくなり、更新前にスケジュールされていたすべての通知を[[UIApplication sharedApplication] cancelAllLocalNotifications].

これらの顧客とコミュニケーションを取りながら、リマインダーをオフにするように言いましたが、cancelAllLocalNotificationsリマインダーを受け取り続けると主張しています。

また、アプリを再インストールしても古い通知は消えません! iOS がこれを別のアプリと認識しているかのようです。

ほとんどのお客様には発生しませんが、ごく一部のお客様にのみ発生しますが、それでも更新のたびに発生します!

どうしてですか?

アップデート

3年経った今でも続いています。

一部の顧客は更新のたびにローカル通知を受信し続けますが、アプリはそれらを見ることも制御することもできません。

誰でもこれを解決したり、iOS のバグであることを証明したりできますか?

4

4 に答える 4

2

アプリの更新間で UIApplication cancelAllLocalNotifications がどのように機能するかを確認しましたか? 決定的な答えはありませんが、役に立つかもしれません。

これを経験したお客様の何が特別なのかを見つけてみてください。

  • この動作を経験するのは常に同じ顧客ですか?
  • 使用している iOS のバージョンは?
  • 彼らはあなたのアプリをどのように使用していますか? たくさんの通知がスケジュールされていますか?
  • 彼らはどのように更新を行っていますか? (無線、同期など)
于 2012-07-12T09:11:17.053 に答える
1

通知に関しても同様の問題がありました。実際に削除する私の解決策は、特定の日付を設定し、一度だけ通知することでした。行 applicationIconBadgeNumber = 0 は、通知リストから通知を削除します。バッジ番号は、ユーザーがアプリに入ったときにのみ設定されます。ユーザーがまだメッセージを表示していない場合は、applicationWillEnterForeground にチェックを追加して、通知と同じメッセージで適切な UIAlertView を表示するだけで、notificationArray を使用して同様の方法で最後の通知を取得できます。新しい通知を設定する必要がある場合は、"isNotified" に setValue:@"0" を設定して同期する必要があります。複数の通知を使用する場合、次のように状態を保存します。

[userDefaults setValue:@"1" forKey:[NSString stringWithFormat:@"notification-%@", @"12"]];
NSInteger number = [[userDefaults objectForKey:[NSString stringWithFormat:@"notification-%@", @"12"]] integerValue];

MainViewController.m 内

NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSInteger alreadyNotified = [[userDefaults objectForKey:@"isNotified"] integerValue];

if (alreadyNotified == 0) {

    NSInteger seconds = 60;
    NSString *message = @"Just testing!";

    UILocalNotification *notification = [[UILocalNotification alloc] init];

    UIUserNotificationSettings *currentSettings = [[UIApplication sharedApplication] currentUserNotificationSettings];
    BOOL allowNotif = (currentSettings.types != UIUserNotificationTypeNone);
    BOOL allowsSound = (currentSettings.types & UIUserNotificationTypeSound) != 0;
    BOOL allowsBadge = (currentSettings.types & UIUserNotificationTypeBadge) != 0;
    BOOL allowsAlert = (currentSettings.types & UIUserNotificationTypeAlert) != 0;

    if (notification)
    {
        if (allowNotif)
        {
            NSDate *now = [NSDate date];
            if (seconds > 0) {
                now = [now dateByAddingTimeInterval:seconds];
            }
            notification.fireDate = now;
            notification.timeZone = [NSTimeZone timeZoneWithName:@"UTC"];
            notification.repeatInterval = 0;
            NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:@"1", @"id", message, @"message", nil];
            notification.userInfo = userInfo;
        }
        if (allowsAlert)
        {
            notification.alertBody = message;
        }
        if (allowsBadge)
        {
            notification.applicationIconBadgeNumber = 1;
        }
        if (allowsSound)
        {
            notification.soundName = UILocalNotificationDefaultSoundName;
        }

        [[UIApplication sharedApplication] scheduleLocalNotification:notification];

        NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
        [userDefaults setValue:@"1" forKey:@"isNotified"];
        [userDefaults synchronize];
    }

} else {

    UIApplication *app = [UIApplication sharedApplication];
    NSArray *notificationArray = [app scheduledLocalNotifications];
    for (int i=0; i<[notificationArray count]; i++)
    {
        UILocalNotification *notification = [notificationArray objectAtIndex:i];
        [app cancelLocalNotification:notification];
    }
}

AppDelegate.m 内

- (void)applicationWillEnterForeground:(UIApplication *)application {
   application.applicationIconBadgeNumber = 0;
}
于 2015-10-18T11:02:57.697 に答える