didRegisterForRemoteNotificationsWithDeviceToken在旧项目中没有调用,但在与旧项目具有相同捆绑ID的新项目中调用?

时间:2016-09-19 08:08:19

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

我确信所有配置都没有问题,包括配置文件和代码,后台模式等。旧项目无法调用'didRegisterForRemoteNotificationsWithDeviceToken'但新项目被调用很奇怪。两个项目都有相同的捆绑包ID,代码和其他配置。

我确信苹果方面没有问题,因为其他人的应用程序可以正常工作,我的新项目也可以。所以我怀疑原因是旧项目做了一些配置,但我不知道。

旧项目由Xcode5制作。 新项目由Xcode7.3制作。

谁能告诉我如何解决这个问题?非常感谢。

以下是AppDelegate中的代码(iOS版本为8.0):

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    if ([UIDevice currentDevice].systemVersion.doubleValue >= 8.0) {

        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil];
        [application registerUserNotificationSettings:settings]

    }else{

        [application registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound];
    }

    return YES;
}

-(void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
    [application registerForRemoteNotifications];
}

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

    NSLog(@"deviceToken ==== %@", deviceToken);  // not called

}

- (void)application:(UIApplication *)application
didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
    NSLog(@"did Fail To Register For Remote Notifications With Error: %@", error); // not called
}

1 个答案:

答案 0 :(得分:0)

您好我遇到了同样的问题。

转到项目目标设置,然后从“功能”中启用推送通知服务。标签。

它会起作用。