我正在使用navBased应用程序中的推送通知。在AppDelegate.m中,didRegisterForRemoteNotificationsWithDeviceToken:不会在调用registerForRemoteNotificationTypes时调用:代码如下所示:

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

    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];

    [self.window addSubview:navigationController.view];
    [self.window makeKeyAndVisible];

    return YES;
}



- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    // Get a hex string from the device token with no spaces or < >
    NSLog(@"applicationDidFinishLaunchingWithOptions dev token test");

    NSString *deviceTokenStr = [[[[deviceToken description]
                          stringByReplacingOccurrencesOfString: @"<" withString: @""]
                         stringByReplacingOccurrencesOfString: @">" withString: @""]
                        stringByReplacingOccurrencesOfString: @" " withString: @""];

    NSLog(@"Device Token: %@", deviceTokenStr);
}

我非常确定配置文件不是问题。我发现错误:

注册错误。错误:错误域= NSCocoaErrorDomain代码= 3000“没有为应用程序找到有效的'aps-环境'权利字符串” UserInfo = 0x115490 {NSLocalizedDescription =没有为应用程序找到有效的'aps-环境'权利字符串}

谁能告诉我这段代码中发生了什么,并且它不起作用?谢谢

最佳答案

检查此:link
并确保打开了5223端口。

10-06 12:48