1

私のアプリでは、プッシュ通知の不能と許可のようなものを使用します。私はこのようなコードを使用します。また、私はsender.isOnregisterusernotificationは、unregisterForRemoteNotificationsを使用した後に動作しません。

if (sender.isOn) { 

    self.notificationLabel.text = @"Notifications enabled"; 

    UIUserNotificationType allNotificationTypes = (UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge); 
    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil]; 
    [[UIApplication sharedApplication] registerUserNotificationSettings:settings]; 
    [[UIApplication sharedApplication] registerForRemoteNotifications]; 

} else { 

    self.notificationLabel.text = @"Notifications disabled"; 

    [[UIApplication sharedApplication] unregisterForRemoteNotifications]; 

} 

からコードを- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptionsに通知をアクティブしかし、最初に使用した後unregisterForRemoteNotifications私のアプリはregisterForRemoteNotificationsで通知をinitiallingありません。私は何が間違っているのか分かりません。

答えて

2

解決方法:アプリケーションをアンインストールして、そのコードを削除してください。

これを追跡するのに、私は多くの時間と3つの壊れたテストデバイスが必要でした。

この行は、悪いです:

[[UIApplication sharedApplication] unregisterForRemoteNotifications] //DON'T DO IT! 

それはregisterForRemoteNotificationsを呼び出すことは、もはや作品不安定な状態でアプリを置きます。あなたのアプリの実行につき、一度だけ

[[UIApplication sharedApplication] registerForRemoteNotifications] //CALL ME ONCE! 

あなたが一度それを呼び出す必要があり、かつ:

この線は均等に厄介です。あなたがそれを2回呼び出すと、通知が不思議に壊れます。

関連する問題