Push notification 推送通知在从ios7到ios8.1的更新版本中不起作用

Push notification 推送通知在从ios7到ios8.1的更新版本中不起作用,push-notification,ios8,apple-push-notifications,xcode6,ios8.1,Push Notification,Ios8,Apple Push Notifications,Xcode6,Ios8.1,我已将设备从ios7更新到ios8.1。推送通知在更新版本中不起作用。 我对推送通知执行了与ios7相同的过程。 代码也会更新 #ifdef __IPHONE_8_0 //Right, that is the point UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge |UIU

我已将设备从ios7更新到ios8.1。推送通知在更新版本中不起作用。 我对推送通知执行了与ios7相同的过程。 代码也会更新

    #ifdef __IPHONE_8_0
      //Right, that is the point
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge
    |UIUserNotificationTypeSound
    |UIUserNotificationTypeAlert) categories:nil];
        [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
#else
    //register to receive notifications
    UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:myTypes];
#endif
通过使用上述代码,我也没有收到通知。请帮助我在ios8.1中获得推送通知


感谢您的改进

接收推送通知的方法也已更改:

- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier
有关更多信息,请参阅和

下面是应用程序委托的完整示例:

- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
        NSLog(@"Requesting permission for push notifications..."); // iOS 8
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:
            UIUserNotificationTypeAlert | UIUserNotificationTypeBadge |
            UIUserNotificationTypeSound categories:nil];
        [UIApplication.sharedApplication registerUserNotificationSettings:settings];
    } else {
        NSLog(@"Registering device for push notifications..."); // iOS 7 and earlier
        [UIApplication.sharedApplication registerForRemoteNotificationTypes:
            UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge |
            UIRemoteNotificationTypeSound];
    }
    return YES;
}

- (void)application:(UIApplication *)application
    didRegisterUserNotificationSettings:(UIUserNotificationSettings *)settings
{
    NSLog(@"Registering device for push notifications..."); // iOS 8
    [application registerForRemoteNotifications];
}

- (void)application:(UIApplication *)application
    didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)token
{
    NSLog(@"Registration successful, bundle identifier: %@, device token: %@",
        [NSBundle.mainBundle bundleIdentifier], token);
}

- (void)application:(UIApplication *)application
    didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
    NSLog(@"Failed to register: %@", error);
}

- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier
    forRemoteNotification:(NSDictionary *)notification completionHandler:(void(^)())completionHandler
{
    NSLog(@"Received push notification: %@, identifier: %@", notification, identifier); // iOS 8
    completionHandler();
}

- (void)application:(UIApplication *)application
    didReceiveRemoteNotification:(NSDictionary *)notification
{
    NSLog(@"Received push notification: %@", notification); // iOS 7 and earlier
}

在我的情况下不工作?我找不到任何关于这些新变化的文件?请提供一些有用的链接