title: Can't receive the push notification message from my php, but the online test site push is can get the message
body: <p>I can't get push notification from my php, But I can get the notification from the <a href="http://apns-gcm.bryantan.info" rel="nofollow noreferrer">online site for testing</a>.</p>
  
  <p>My iOS project step is below:</p>
  
  <ol>
  <li><p>add the setting Capabilities change to on for "Push notifications", And Background Mode selected the "remote notifications" and "background fetch".</p></li>
  <li><p>add the " UserNotifications.frameworks"</p></li>
  <li><p>In the AppDelegate add the ""</p></li>
  </ol>
  
  <p>4.In the Appdelegate.m  add below code:</p>
  
  <pre><code> - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  // Override point for customization after application launch.
  UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
  center.delegate = self;
  [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){
      if( !error )
      {
          [[UIApplication sharedApplication] registerForRemoteNotifications];  // required to get the app to do anything at all about push notifications
          NSLog( @"Push registration success." );
      }
      else
      {
          NSLog( @"Push registration FAILED" );
          NSLog( @"ERROR: %@ - %@", error.localizedFailureReason, error.localizedDescription );
          NSLog( @"SUGGESTIONS: %@ - %@", error.localizedRecoveryOptions, error.localizedRecoverySuggestion );
      }
  }];
  
  [center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
      NSLog(@"push settings:%@",settings);
  }];
  
  return YES;
   }
  
   - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken NS_AVAILABLE_IOS(3_0){
  
  NSString *deviceTokenString = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@""]];
  deviceTokenString = [deviceTokenString stringByReplacingOccurrencesOfString:@" " withString:@""];
  NSLog(@"device token:%@",deviceTokenString);
  
   }
  
  
   -(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler{
  
       UNNotificationRequest *request = notification.request;
  
          UNNotificationContent *content = request.content;
  
          NSDictionary *userInfo = content.userInfo;
  
          NSNumber *badge = content.badge;
  
          NSString *body = content.body;
  
  UNNotificationSound *sound = content.sound;
  
  NSString *subtitle = content.subtitle;
  
  NSString *title = content.title;
  
  if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
  
      NSLog(@"iOS10 get remote notify:%@",userInfo);
  
  }else {
  
      NSLog(@"iOS10 get local notify:{\\\\nbody:%@，\\\\ntitle:%@,\\\\nsubtitle:%@,\\\\nbadge：%@，\\\\nsound：%@，\\\\nuserInfo：%@\\\\n}",body,title,subtitle,badge,sound,userInfo);
  }
  
  
  completionHandler(UNNotificationPresentationOptionBadge|
                    UNNotificationPresentationOptionSound|
                    UNNotificationPresentationOptionAlert);
   }
  
      // notify click event
   - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler{
  
  UNNotificationRequest *request = response.notification.request;
  
  UNNotificationContent *content = request.content;
  
  NSDictionary *userInfo = content.userInfo;
  
  NSNumber *badge = content.badge;
  
  NSString *body = content.body;
  
  UNNotificationSound *sound = content.sound;
  
  NSString *subtitle = content.subtitle;
  
  NSString *title = content.title;
  
  if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
      NSLog(@"iOS10 remote notify:%@",userInfo);
  
  
  }else {
              NSLog(@"local notify:{\\\\nbody:%@，\\\\ntitle:%@,\\\\nsubtitle:%@,\\\\nbadge：%@，\\\\nsound：%@，\\\\nuserInfo：%@\\\\n}",body,title,subtitle,badge,sound,userInfo);
  }
  
  
  completionHandler();
   }
  </code></pre>
  
  <ol start="5">
  <li>I can get the below log:</li>
  </ol>
  
  <blockquote>
    <p>push settings UNNotificationSettings 0x170089510： 
    authorizationStatus, Authorized, notificationCenterSetting, Enabled, 
    soundSetting, Enabled, badgeSetting：Enabled, lockScreenSetting： 
    Enabled, alertSetting： NotSupported, carPlaySetting： Enabled, 
    alertStyle , Alert</p>
    
    <p>Push registration success.</p>
    
    <p>device token：my device token ID</p>
  </blockquote>
  
  <ol start="6">
  <li>I set the PHP code like below:</li>
  </ol>
  
  <blockquote>
  <pre><code>&lt;?php
  
  
   $deviceToken = $row['my device token ID'];
  // Put your private key's passphrase 
  $passphrase = 'my password';
  $message = 'My first push notification!';
  ////////////////////////////////////////////////////////////////////////////////
  $ctx = stream_context_create();
  stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
  stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
  stream_context_set_option($ctx, 'ssl', 'cafile', 'entrust_2048_ca.cer');
  // Open a connection to the APNS server
  $fp = stream_socket_client(
   'ssl://gateway.sandbox.push.apple.com:2195', $err,
   $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
  // $fp = stream_socket_client(
  //  'ssl://gateway.push.apple.com:2195', $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;
  // Create the payload body
  $body['aps'] = array('alert' =&gt; $message,'sound' =&gt; 'default');
  // Encode the payload as JSON
  $payload = json_encode($body);
  // Build the binary notification
  $msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
  // Send it to the server
  $result = fwrite($fp, $msg, strlen($msg));
  if (!$result)
   echo 'Message not delivered' . PHP_EOL;
  else
   echo 'Message successfully delivered' . PHP_EOL;
  // Close the connection to the server
  fclose($fp);
  ?&gt;
  </code></pre>
  </blockquote>
  
  <ol start="7">
  <li><p>then I run the php in my mac, I run the localhost/push.php , I can get the message from the web:</p>
  
  <p><strong>Connected to APNS Message successfully delivered</strong></p></li>
  <li><p>But I can't get the any log in my app, and can't get the message notification.</p></li>
  </ol>
  
  <p>I am use the development certificate and provision, so my test push site is set the gateway.sandbox.push.apple.com:2195.</p>
  
  <p>Have anyone known why I can't get the notification, but I can get the notification from the online test site?</p>
  
  <p>Thank you very much.</p>