推送通知不一致

问题描述:

工作的情景:当我从Xcode中运行我的应用程序直接到我的设备,我可以在服务器上运行一个推送通知,并预期它会成功。推送通知不一致

非工作场景:我将应用导出到IPA并通过iTunes将应用安装到我的设备上。当我推送来自服务器的通知时,我会得到错误ERROR: Unable to send message ID 1: Invalid token (8).

在写这篇文章时,我有一个想法,并检查设备ID,当它来自Xcode安装与IPA安装,他们是不同的!发送设备ID到我的服务器

代码:

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { 
    // You can send here, for example, an asynchronous HTTP request to your web-server to store this deviceToken remotely. 

    // convert token to a single string 
    NSString *token = [[[deviceToken description] 
         stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]] 
         stringByReplacingOccurrencesOfString:@" " 
         withString:@""]; 

    NSString *post = [NSString stringWithFormat:[NSString stringWithFormat:@"token=%@", token]]; 
    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; 

    NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]]; 

    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; 
    [request setURL:[NSURL URLWithString:@"http://mywebsitename.com/ApnsPHP/add.php"]]; 
    [request setHTTPMethod:@"POST"]; 
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"]; 
    [request setHTTPBody:postData]; 

    [NSURLConnection sendAsynchronousRequest:request queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error){ 
     dispatch_async(dispatch_get_main_queue(), ^{ 
      NSError *e = nil; 
      NSDictionary *dict = [XMLReader dictionaryForXMLData:data error:&e]; 
      NSLog(@"response from server: %@", dict); 
     }); 
    }]; 

    NSLog(@"Did register for remote notifications: %@", deviceToken); 
} 

我怎样才能得到它,以便从IPA分发的设备令牌经历?谢谢。

我仔细阅读相关的问题时,我发现this question about push notes。我想到了这个想法,并开始检查自上而下的事情。我终于发现了这一点:

Apple Push Notification Developer View

希望这些问题是你作为明显的,因为它是给我,但我明白,如果不是这样的。的APN不会与IPA,除非为生产推送SSL证书Enabled状态工作。

Xcode的安装是开发版本,是的.ipa生产/即兴,他们有不同的证书。仔细阅读远程通知指南!

+1

我已经做了'release'级证书,但如果我的证书是错误的,那么为什么我的设备释放令牌呢? – Jacksonkr 2012-07-08 23:29:10