工作的情景:當我從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分發的設備令牌經歷?謝謝。
我已經做了'release'級證書,但如果我的證書是錯誤的,那麼爲什麼我的設備釋放令牌呢? – Jacksonkr 2012-07-08 23:29:10