簡體   English   中英

在iOS7上沒有調用didRegisterForRemoteNotificationsWithDeviceToken

[英]didRegisterForRemoteNotificationsWithDeviceToken not called on iOS7

我經常要求通知令牌:

if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
    [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
    [application registerForRemoteNotifications];
} else {
    [application registerForRemoteNotificationTypes:
     (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
}

然而didRegisterForRemoteNotificationsWithDeviceToken回調在我的iOS 8 iPad上一直被調用,從不在我的iOS 7 iPhone上(甚至不是didFailToRegisterForRemoteNotificationsWithError),甚至沒有刪除應用程序並重新安裝它:也沒有顯示警報。 我檢查了我的iPhone中的證書和設置,但所有看起來都是有序的,以及測試SO和整個互聯網上的所有建議,但似乎沒有什么可以修復它。 還有什么建議嗎?

這可能是由於權限拒絕。 應用程序卸載不會重置此權限。

為了驗證是否拒絕此權限,請執行以下操作( iOS7 ):

[[UIApplication sharedApplication] enabledRemoteNotificationTypes] != UIRemoteNotificationTypeNone;

如果權限被拒絕,則必須執行以下步驟:

  1. 重置設備設置中的權限
  2. 刪除應用程序
  3. 提前兩天移動設備時鍾
  4. 重啟手機
  5. 安裝應用程序並再次運行

    • 在通知權限彈出后,不要忘記設置時鍾。

檢查Xcode項目目標中的以下設置:目標項目>功能>推送通知啟用推送通知並檢查是否已將“推送通知”權利添加到您的應用程序ID。

我正在使用以下“代碼”並為我工作。

 [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];

嘗試這個,

    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
    {
        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
        [[UIApplication sharedApplication] registerForRemoteNotifications];
    }
    else
    {
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
         (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
    }

希望這可以幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM