Working scenario: When I run my app from xcode directly to my device I can run a push notification on the server and it works just as expected.
Non-working scenario: I export the app to an IPA and install the app on my device via iTunes. When I push a notification from the server I’ll get the error of ERROR: Unable to send message ID 1: Invalid token (8).
While writing this post I had a thought and checked the device id when it came from the xcode install vs the IPA install and they are different!
code for sending the device id to my server:
- (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);
}
How can I get it so that the device token from the IPA distribution goes through? Thanks.
I was perusing related questions when I found this question about push notes. I thought about the idea and started checking out things from top to bottom. I finally found this:
Hopefully the problem is as apparent to you as it was to me, but I understand if it’s not. APNs will not work with an IPA unless the status for the Production Push SSL Certificate is
Enabled.