簡體   English   中英

iOS8-詢問遠程推送通知

[英]iOS8 - Asking for remote push notifications

關於iOS8中的變化的兩個問題,供用戶接受推送通知(以及徽章等通知)。

1)我正在使用目前在iOS7和iOS8上都能正常工作的方法

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

這完全可以正常工作,因為推送和警報都在工作,並且我在didRegister委托方法中獲得了令牌,但是從沒有像過去那樣用彈出窗口詢問我。 即使我從手機上完全刪除了該應用程序? 為什么? 操作系統是否已保留應用程序的內存隱私設置(即使已被刪除)?

2)我看到有人建議在以下代表中要求遠程通知

- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{        
    NSLog(@"registered for notifications settings %@",notificationSettings);        
    //register to receive notifications
    [application registerForRemoteNotifications];
} 

為什么 ?

在文檔中- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings此方法回調將在調用- [UIApplication registerUserNotificationSettings:] 用戶已授予應用程序的設置將作為第二個參數傳遞。 這意味着,一旦獲得用戶許可(或者如果已經獲得許可),則將調用此方法,在此我們可以通過調用[application registerForRemoteNotifications]用於遠程通知的[application registerForRemoteNotifications]

暫無
暫無

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

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