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