iPhone 6(iOS 8)中的推送通知不起作用

时间:2015-03-13 07:39:02

标签: ios objective-c apple-push-notifications ios8.1 iphone-6

以下是我在appDelegate中编写的与Apple推送通知相关的代码。对我来说,这是一个奇怪的问题,我没有收到IPHONE6 IOS8中的推送通知,而是接收其他设备和其他版本的推送。如果我缺少某些东西,我是否需要为IPHONE6 IOS8做其他事情。请建议帮我解决问题。

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

pragma mark - 远程通知代理

#ifdef __IPHONE_8_0
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
    //register to receive notifications
  [application registerForRemoteNotifications];
}
#endif

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

0 个答案:

没有答案