12
votes

I've been working on this for a while now. I know there's a ton of articles out there, and have learned a lot about it all.

I have created my development and production SSL's the same way. Development connects to ssl://gateway.sandbox.push.apple.com:2195 Production connects to ssl://gateway.push.apple.com:2195 The connections seem to work fine.

As for the app. Development: When I run it directly on to my device from xCode, it runs the development version. The app successfully records the development token in the database. I then run a service to send a push notification, and it is delivered correctly. The msg is successfully delivered.

Ad-hoc: When I build an archive and export it for Ad-hoc distribution, I double check the package contents codesign -dvvvv --entitlements - Elepago.app and see that the aps-environment is correctly set to production. I package it and load it onto my device through iTunes. When the app starts, I see the new production token recorded in the database. So the environment must be correctly set up. When I send the push notification to the production key (identically the same as development, just changing the SSL .pem key and the server), it says it is successfully delivered. However it never actually reaches the device!!!

This problem is driving me crazy. I just went through and cleaned out my distribution certificate and rebuilt it using a completely new CSR. I also updated all the provisioning profiles to use that new certificate. [Any ideas how these certificates tie into the app, other than for the aps-environment thing which I already check.]

Any insight would be greatly appreciated.

4
are the notifications enabled for your app in Settings -> Notification?feco
thanks for the help. they are (push notifications do work on development). And even on the production version, I am getting the push key everytime, so those permissions seem to be all in order...Federico
@Federico Are you sure you are sending the notification to the production device token?Eran
Yeah. I'm doing the tests manually. Whenever I load the development version of the app (straight from xCode), the device registers the development pn token to the db. It is consistently the same on this version. I take that key and manually put it into my php file to test. And the pn gets delivered. When I run it adhoc, the pn token in the db changes - I assume bc its the production token. When I replace the token, change the servers&ssl cert in the php to production, I don't get anything. No push notification on the device. No error msg.Federico
The existence of separate "developer" and "production" device tokens held me up for a couple hours of testing. Where is it mentioned that the token is different in each case?GoldenJoe

4 Answers

8
votes

So after hours and hours of headaches, I ended up rebuilding the SSL .pem file and it worked!!

Here's what I did:

  • wiped clean my distribution certificate and created a new one
  • associated all provisioning profiles to new certificate
  • loaded up new provisioning profiles in xCode
  • rebuilt my SSL handshake .pem file following instructions on Raywenderlich's awesome tutorials

These are the same instructions I had originally followed for development and production, but maybe/apparently messed something up. Then I tested on my ad-hoc version and it worked!!!

Also, its worth noting that when using the wrong .pem key, I was not receiving any error feedback from APNS. I use the simplepush.php file found in the link above as a base to send the PN.

4
votes

Device token for Development and Production are not same.

When you are testing for Production use UIAlertView to see your token for Production. Do something like the following:

- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
    NSString *deviceID = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
    deviceID = [deviceID stringByReplacingOccurrencesOfString:@" " withString:@""];
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Device Token", nil) message:deviceID delegate:nil cancelButtonTitle:NSLocalizedString(@"OK", nil) otherButtonTitles:nil];
    [alert show];
}

Use this token to push notification for production.

1
votes
  • Any in-house distribution profile gives out a same tokenID, how ever this tokenID varies across different devices.
  • Other only issue could be only with the ProductionURL.
  • I have also notices that the push notification reception is delayed sometimes, mostly when used with production URL.

Hope this helps.

0
votes

My problem is the same when I developed on Java But I solved it because of production = true is for production and production = false for development.

payload (payload, keystore, password, production, devices)

Hope this help.