2015-03-31 179 views
2

一直被困在這個上,但無法獲得以下方法被調用。我可以讓手機申請許可,但之後就卡住了。不被調用的方法: - (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)在下面的計算器後提供的一切:why didRegisterForRemoteNotificationsWithDeviceToken is not called

2)從蘋果看這個技術說明: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; 
} 
+0

是iOS8嗎?還確實被叫做註冊表? – vichevstefan 2015-03-31 22:02:26

+0

都不叫,iOS8 – John 2015-04-01 00:42:42

+0

APNS證書安裝在生成機器上,還更新了配置文件? – gagarwal 2015-04-01 05:11:47

回答

0

的iOS 8引入了登記流程的改變,需要明確的要求越來越之後註冊遠程通知來自用戶的許可。

您正在調用此代碼?

[[UIApplication sharedApplication] registerUserNotificationSettings: settings]; 

並在您的應用程序委託中執行此操作?

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

這就是說,現在舊的API已被棄用,但仍需要,如果你計劃支持的iOS 7.支持您可以檢查,看看是否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]; 
} 
+0

查看已添加編輯/評論看看我曾經打過電話。謝謝! – John 2015-04-01 04:19:30

+0

在if塊的iOS 8部分中,您需要刪除對'[application registerForRemoteNotifications]'的調用。在應用程序委託中實現'didRegisterUserNotificationSettings:'回調,並在該方法中調用'registerForRemoteNotifications'調用。 'registerForRemoteNotifications'調用在完成權限請求之後纔會起作用。 – 2015-04-01 13:50:53

+0

我之前做過如下操作: - (void)application:(UIApplication *)applicationDisRegisterUserNotificationSettings :(UIUserNotificationSettings *)notificationSettings { NSLog(@「IOS8 VERSION」); [application registerForRemoteNotifications]; } – John 2015-04-01 19:00:46

相關問題