1

我在使用真實設備生成設備令牌時遇到了問題。 我正在調試設備和設備令牌沒有生成。 有時它有效,有時不起作用。設備令牌不生成iOS

請讓我知道可能是什麼問題。 謝謝

+0

有時會有效,有時不會:在同一臺設備上?各種設備?各種iOS版本?錯誤回調是否被調用? – Larme

+0

我不認爲這是一個很好的做法,兩次問同一件事。在你的兩個問題中,你沒有提供任何細節,代碼,iOS版本等,你沒有顯示任何研究工作。我強烈建議您刪除其中一個問題,並在您保留的問題中儘可能包含有關該問題的詳細信息。乾杯! –

回答

0

@GopalDevra你能更清楚嗎?無論如何,我有這個代碼解析,也許這不是你的情況,但你可以明白。

可以在AppDelegate.m使用didRegisterForRemoteNotificationsWithDeviceToken像:

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { 

    // Store the deviceToken in the current installation and save it to Parse. 
    PFInstallation *currentInstallation = [PFInstallation currentInstallation]; 
    [currentInstallation setDeviceTokenFromData:deviceToken]; 
    currentInstallation.channels = @[ @"global" ]; 
    [currentInstallation saveInBackground]; 
} 

編輯

你把這個在didFinishLaunchingWithOptions?

// - Push notifications 
// -- Register for Push Notitications 
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert | 
               UIUserNotificationTypeBadge | 
               UIUserNotificationTypeSound); 
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes 
                     categories:nil]; 

[application registerUserNotificationSettings:settings]; 
[application registerForRemoteNotifications]; 

//-- Set Notification 
if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)]) 
{ 
    // iOS 8 Notifications 
    [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]]; 

    [application registerForRemoteNotifications]; 
} 
else 
{ 
    // iOS < 8 Notifications 
    [application registerForRemoteNotificationTypes: 
    (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];   
} 

//--- your custom code 
+0

非常感謝 我試過這些代碼行。 但不工作 –

+0

@GopalDevra我更新了我的答案。一探究竟。 –

+0

@ J.Lopes您今天能夠從沙箱APN獲取設備令牌嗎? –

1

你把下面的AppDelegate.mdidFinishLaunchingWithOptions

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) 
{ 
    NSLog(@"ios8 app"); 
    [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]]; 
    [[UIApplication sharedApplication] registerForRemoteNotifications]; 
} 
else 
{ 
    NSLog(@"lower ios8 app"); 
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)]; 
} 
0

添加這種方法,

func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) 
    { 
     print("application:didFailToRegisterForRemoteNotificationsWithError: %@", error) 
    } 

你會得到答案,也不會產生爲什麼令牌。

+0

Edit for objective c :-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { } –

1

截至目前,我也無法獲得設備令牌。

我的項目在10小時前「擦除」和「安裝」時停止生成設備令牌。 也在韓國iOS開發者論壇上,有些人一直在報告過去10個小時內沒有生成APNS令牌的問題。

某些沙箱APNS服務器可能有問題。

  • 最後檢查時間 2016年4月27日22:43 PM 0900 GMT:沒有設備令牌,推送通知沒有到達。
+0

這是真的發生了@CheeseLemon? –

+0

是的,現在每個人都在報告它現在正在工作。 – CheeseLemon