14

I am using the apns php server provided at https://code.google.com/p/apns-php/.

I've have set up th push notification certificate but my code still throws an error on connect.

What is wrong with this? Here is how I get the device token:

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {

#if !TARGET_IPHONE_SIMULATOR

    // Prepare the Device Token for Registration (remove spaces and < >)
    NSString *deviceToken = [[[[devToken description]
                               stringByReplacingOccurrencesOfString:@"<"withString:@""]
                              stringByReplacingOccurrencesOfString:@">" withString:@""]
                             stringByReplacingOccurrencesOfString: @" " withString: @""];
    NSLog(@"%@", deviceToken);

#endif
}

This is the error when I run my server:

Sat, 11 May 2013 13:37:53 -0700 ApnsPHP[18198]: INFO: Trying 
ssl://gateway.push.apple.com:2195...
Sat, 11 May 2013 13:37:54 -0700 ApnsPHP[18198]: INFO: Connected to ssl://gateway.push.apple.com:2195.
Sat, 11 May 2013 13:37:54 -0700 ApnsPHP[18198]: INFO: Sending messages queue, run #1: 1 message(s) left in queue.
Sat, 11 May 2013 13:37:54 -0700 ApnsPHP[18198]: STATUS: Sending message ID 1 [custom identifier: abc123] (1/3): 101 bytes.
Sat, 11 May 2013 13:37:54 -0700 ApnsPHP[18198]: ERROR: Unable to send message ID 1: Invalid token (8).
Sat, 11 May 2013 13:37:54 -0700 ApnsPHP[18198]: INFO: Disconnected.
Sat, 11 May 2013 13:37:54 -0700 ApnsPHP[18198]: INFO: Trying ssl://gateway.push.apple.com:2195...
Sat, 11 May 2013 13:37:54 -0700 ApnsPHP[18198]: INFO: Connected to ssl://gateway.push.apple.com:2195.
Sat, 11 May 2013 13:37:54 -0700 ApnsPHP[18198]: INFO: Sending messages queue, run #2: 1 message(s) left in queue.
Sat, 11 May 2013 13:37:54 -0700 ApnsPHP[18198]: WARNING: Message ID 1 [custom identifier: abc123] has an unrecoverable error (8), removing from queue without retrying...
Sat, 11 May 2013 13:37:55 -0700 ApnsPHP[18198]: INFO: Disconnected.
maxhb
  • 8,554
  • 9
  • 29
  • 53
Jason Silberman
  • 2,471
  • 6
  • 29
  • 47
  • Did you use an Ad-Hoc provisioning profile with this build? Else a production certificate will not work. – edwardmp May 12 '13 at 11:09

1 Answers1

26

The most likely explanation is that you are sending a push notification with a sandbox device token to the production APNS server.

Either you are using an old device token that was sent to your server by your app while you were testing it in the sandbox environment, or your app is still signed with a development provisioning profile, and is still receiving sandbox device tokens from the APNS service.

My answer assumes that you are using a device token that originated from the APN service, and not some dummy token you created yourself .

I suggest you check the provisioning profile to see what value appear for the aps entitlement. I also suggest you clear your db from any old device tokens.

Eran
  • 387,369
  • 54
  • 702
  • 768
  • hmm... Now it's not throwing an error that I changed to the sandbox but my device still isn't receiving the notification as far as I can tell. – Jason Silberman May 12 '13 at 22:17
  • @JasonSilberman What exactly did you change to the sandbox? The app or the server? If you're using the wrong certificate at the server (using sandbox push ceritificate to connect to the production APNS server or vice versa) the device won't receive anything, and the server won't get any error response. – Eran May 12 '13 at 22:51
  • I'm using the sandbox gateway and the sandbox certificate – Jason Silberman May 13 '13 at 01:26
  • And your app has a sandbox aps entitlement? – Eran May 13 '13 at 03:14
  • 1
    The `aps` entitlement should appear in the provisioning profile that you signed your app with. You should look for `` in your profile and see if it's value is `development` or `production`. – Eran May 13 '13 at 15:40
  • Is there a way for one's server to tell, from the token, whether it's a development token or production token? – user102008 Jan 23 '14 at 22:50
  • @Eran asp-environment for a build signed with adhoc profile should be "production" right? – hariszaman Oct 18 '16 at 11:22
  • 1
    @Eran can you please check my question and see if something is still missing. Everything seems to be correct but still I am getting the same error http://stackoverflow.com/questions/40152981/apns-not-working-with-adhoc-build – hariszaman Oct 20 '16 at 11:29