设备令牌不生成iOS

时间:2016-04-27 12:24:44

标签: ios objective-c iphone push-notification apple-push-notifications

我在使用真实设备生成设备令牌时遇到问题。 我正在调试设备和设备令牌没有生成。 有时候它有效,有时却没有。

请告诉我可能存在的问题。 感谢

4 个答案:

答案 0 :(得分:1)

您是否在didFinishLaunchingWithOptions AppDelegate.m的{​​{1}}下面了?

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)];
}

答案 1 :(得分:1)

截至目前,我也无法获取设备令牌。

我的项目在10小时前“擦除”和“安装”时停止生成设备令牌。 同样在韩国iOS开发者论坛中,有些人报告过在过去10小时内没有产生APNS令牌的问题。

某些沙盒APNS服务器可能有问题。

  • 上次检查时间 2016-04-27 22:43 PM +0900 GMT:没有设备令牌,推送通知未到达。

答案 2 :(得分:0)

@PopalDevra你能说得更清楚吗?无论如何,我有这个代码用于Parse,也许这不是你的情况,但你可以得到这个想法。

您可以在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

答案 3 :(得分:0)

添加此方法,

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

您将得到答案,为什么不生成令牌。

相关问题