didRegisterForRemoteNotificationsWithDeviceToken:在调用registerForRemoteNotificationTypes时不调用:?

Pis*_*ean 10 iphone push-notification apple-push-notifications ios-4.2

我正在使用基于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);
}
Run Code Online (Sandbox Code Playgroud)

我很确定配置文件不是问题所在.我发现错误:

注册时出错.错误:错误Domain = NSCocoaErrorDomain Code = 3000"为应用程序找到无效的'aps-environment'权利字符串"UserInfo = 0x115490 {NSLocalizedDescription =找不到应用程序的有效'aps-environment'权利字符串}

任何人都可以告诉我这个代码中发生了什么,并且它不起作用?感谢名单

小智 7

在Appdelegate didFinishLaunching方法中输入此代码 -

[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
     (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
Run Code Online (Sandbox Code Playgroud)

然后还可以在同一个appdelegate中复制并粘贴这两个方法 -

- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
    NSLog(@"My token is: %@", deviceToken);
        NSString *dToken = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
    dToken = [dToken stringByReplacingOccurrencesOfString:@" " withString:@""];


    NSLog(@"STR%@",dToken);


- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{

    NSLog(@"Failed to get token, error: %@", error);
}
Run Code Online (Sandbox Code Playgroud)


Max*_*Max 3

检查这个:链接 并确保您已打开 5223 端口。