簡體   English   中英

未調用方法:-(void)應用程序:(UIApplication *)應用程序didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken

[英]Method not being called: - (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken

一直堅持下去,但是無法調用以下方法。 我能夠得到電話以請求許可,但是之后卡住了。

- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
    NSLog(@"My token is: %@", deviceToken);
}

- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
    NSLog(@"Failed to get token, error: %@", error);
}

我嘗試了很多事情,包括:

1)以下stackoverflow帖子中提供的所有內容: 為什么未調用didRegisterForRemoteNotificationsWithDeviceToken

2)查看Apple提供的技術說明: https//developer.apple.com/library/ios/technotes/tn2265/_index.html

3)整個教程: http : //www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1 (所以希望我的證書都不錯)

4)(是的,我可以連接互聯網)

有誰有任何可能的解決方案? 最近2-3天,我一直在動腦筋,已經不得不兩次將手機恢復出廠設置,並且需要將手機上的日期更改N次,以使通知彈出窗口顯示為一遍又一遍地測試。

希望有幫助! 謝謝!

這是我用來打電話的內容...(嘗試了其他幾個版本):

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    //other stuff not related

    if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
    #ifdef __IPHONE_8_0
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert) categories:nil];
        [application registerUserNotificationSettings:settings];
        [application registerForRemoteNotifications];
    #endif
    } else {
        UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
        [application registerForRemoteNotificationTypes:myTypes];
    }

    return YES;
}

iOS 8對注冊流程進行了更改,要求在獲得用戶許可后明確要求注冊遠程通知。

您正在調用此代碼?

[[UIApplication sharedApplication] registerUserNotificationSettings: settings];

並在您的應用程序委托中實現它?

- (void) application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
    [application registerForRemoteNotifications];
}

也就是說,舊的API現在已被棄用,但是如果您打算支持iOS 7,則仍然需要這些API。要同時支持這兩種API,可以檢查UIApplication是否響應新的選擇器:

if ([[UIApplication sharedApplication] respondsToSelector:@SEL(registerUserNotificationSettings:)]) {
    // iOS 8
    [[UIApplication sharedApplication] registerUserNotificationSettings: settings];

    // [[UIApplication sharedApplication] registerForRemoteNotifications] 
    // will be called in your UIApplicationDelegate callback
} else {
    // iOS 7
    [[UIApplication sharedApplication] registerForRemoteNotifications];
}

暫無
暫無

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

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