2012-07-06 55 views
0

工作的情景:當我從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分發的設備令牌經歷?謝謝。

回答

1

我仔細閱讀相關的問題時,我發現this question about push notes。我想到了這個想法,並開始檢查自上而下的事情。我終於發現了這一點:

Apple Push Notification Developer View

希望這些問題是你作爲明顯的,因爲它是給我,但我明白,如果不是這樣的。的APN不會與IPA,除非爲生產推送SSL證書Enabled狀態工作。

1

Xcode的安裝是開發版本,是的.ipa生產/即興,他們有不同的證書。仔細閱讀遠程通知指南!

+1

我已經做了'release'級證書,但如果我的證書是錯誤的,那麼爲什麼我的設備釋放令牌呢? – Jacksonkr 2012-07-08 23:29:10