title: Apple Push Notification is not delivered
body: <p>I know it's a little bit flooded with Apple's Push Notification Service (APNs) issues all over StackOverflow so I actually did a lot of researches before coming up my question.</p>
  
  <p>Basically, I have followed the <a href="http://code.google.com/p/apns-php/wiki/CertificateCreation" rel="noreferrer">apns-php's CertificateCreation</a>, some tutorial like <a href="http://mobiforge.com/developing/story/programming-apple-push-notification-services" rel="noreferrer">on mobiforge</a>, and some from <a href="http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12" rel="noreferrer">Matthijs Hollemans</a>. Still, I can't get any notification posted onto my iPad 2.</p>
  
  <p>Basically these are the steps I have done:</p>
  
  <ol>
  <li>I followed the <a href="http://code.google.com/p/apns-php/wiki/CertificateCreation" rel="noreferrer">CertificateCreation</a> tutorial, I came out with <code>server_certificates_bundle_sandbox.pem</code>, <code>entrust_root_certification_authority.pem</code>.</li>
  <li><p>Followed the tutorial specified in <a href="http://mobiforge.com/developing/story/programming-apple-push-notification-services" rel="noreferrer">mobiforge blog</a>, I successfully created the App ID, provisioning profile and linked them together nicely.</p>
  
  <ul>
  <li>Description: <strong>APNTest</strong></li>
  <li>Bundle Seed ID: <strong>Use Team ID</strong></li>
  <li>Bundle Identifier: <strong>com.learn.APN</strong></li>
  </ul></li>
  <li><p>Then I enable the Development Push SSL Certificate (only for now) using the same certificate request I have used just now to get the certs, and I download it and install it into my keychain.</p></li>
  <li><p>I downloaded my provisioning profile in <code>.mobileprovision</code> file and loaded it into Xcode's Organizer under my iPad 2 device.</p></li>
  <li><p>Next I create a simple application with only these codes:</p>
  
  <pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  {
      [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
      // Override point for customization after application launch.
      return YES;
  }
  
  - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
  {
      NSLog(@"%@", deviceToken);
  }
  
  - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
  {
      NSLog(@"Error: %@", error);
  }
  </code></pre></li>
  <li><p>Then I configure the build parameters:</p>
  
  <ul>
  <li>Targets > Info > Build Identifier: <strong>net.learn.APN</strong></li>
  <li>Targets > Build Settings > Code Signing Identity > (I chose the provisioning profile I have installed just now, and it automatically selects the identical profiles for my Debug and Release)</li>
  </ul></li>
  <li><p>I build and run the application on my iPad 2. My application requesting for Push Notification and after I approved it, the Token ID appeared in my console:</p>
  
  <pre><code>2012-01-19 12:43:26.345 TestAPN[578:707] &lt;3cb08612 9392996b 5332d2fc 5adce03d 994f8959 d7a2ac38 de7bed52 c8e0778e&gt;
  </code></pre></li>
  <li><p>I used <a href="http://code.google.com/p/apns-php/" rel="noreferrer">apns-php</a>, changed the device ID (raw 64 hexa-values), then run the <code>sample_push.php</code>. Script ran successfully, but my device is not receiving any notification</p></li>
  <li><p>Then I try to use the <a href="http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12" rel="noreferrer">SimplePush.php</a>. A "Message successfully delivered" appeared, but my iPad still doesn't receive any notification from APN</p></li>
  </ol>
  
  <p>Question is, which steps have I done wrongly? I'm pretty newbie in this area, and it is actually a requirement for my project that the server need to send out messages to our own applications. We are aware of the third party softwares that send APN on behalf of you, but we would like to implement one ourselves.</p>
  
  <p>I also came across the "<a href="https://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingWIthAPS/CommunicatingWIthAPS.html#//apple_ref/doc/uid/TP40008194-CH101-SW3" rel="noreferrer">APN Feedback Service</a>" and I written this (base on the SimplePush) but sadly it's empty. What should I do now?</p>
  
  <pre><code>&lt;?php
  // Put your private key's passphrase here:
  $passphrase = '';
  
  $ctx = stream_context_create();
  stream_context_set_option($ctx, 'ssl', 'local_cert', 'server_certificates_bundle_sandbox.pem');
  stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
  
  // Open a connection to the APNS server
  $fp = stream_socket_client(
          'ssl://feedback.sandbox.push.apple.com:2196', $err,
          $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
  
  if (!$fp)
          exit("Failed to connect: $err $errstr" . PHP_EOL);
  
  echo 'Connected to APNS' . PHP_EOL;
  
  while (!feof($fp)) {
          $data = fgets($fp, 1024);
          var_dump(unpack("N1timestamp/n1length/H*devtoken", $data));
  }
  // Close the connection to the server
  fclose($fp);
  </code></pre>
  
  <p><strong>Note</strong></p>
  
  <ol>
  <li>I am aware of the differences between development/production certs.</li>
  <li>iPad is not jailbroken, running iOS 5.0.1</li>
  <li>Other App Store apps receives notifications normally</li>
  <li>XCode 4.2.1, Lion 10.7.2</li>
  </ol>
  
  <p>I hope I'm not duplicates any of the questions here.. ;)</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>When I run <code>php simplepush.php</code> then <code>php feedback.php</code>, I received a feedback with my device ID. My App is still in the iPad, so does it mean my device ID is wrong?</p>
  
  <pre><code>[root@ip-xx-xx-xx-xx SimplePush]# php feedback.php
  Connected to APNS
  array(3) {
    ["timestamp"]=&gt;
    int(1326962028)
    ["length"]=&gt;
    int(32)
    ["devtoken"]=&gt;
    string(64) "3cb086129392996b5332d2fc5adce03d994f8959d7a2ac38de7bed52c8e0778e"
  }
  </code></pre>
  
  <p>Thanks</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>After much struggling and redoing all the steps written by <a href="http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12" rel="noreferrer">Matthijs Hollemans</a>, I finally get it working. So the problem lies within the incorrect PEM file generated... hmm</p>