面临推送通知的问题

时间:2015-04-21 10:36:27

标签: php ios

我的应用中的推送通知存在问题。我跟着this tutorial作为编程推送通知的示例。我跑的时候:

php simplepush.php
服务器上的

,每次“消息成功发送”,但只有部分设备收到通知。

2 个答案:

答案 0 :(得分:2)

我遇到了类似的问题,问题在于你的simplepush.php文件。

我通过为每个用户打开和关闭流套接字来修复它。通过这样做解决了我的问题。

示例代码

foreach($iosUsers as $userDetails)
{
   // 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);

    if (!$fp)
     exit("Failed to connect: $err $errstr" . PHP_EOL);

   // Build the binary notification
   $msg = chr(0) . pack('n', 32) . pack('H*', $userDetails) . 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;

  fclose($fp);


}

答案 1 :(得分:0)

替换此行

[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
        (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];

if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
    {
        // iOS 8 Notifications
        [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];

        [application registerForRemoteNotifications];
    }
    else
    {
        // iOS < 8 Notifications
        [application registerForRemoteNotificationTypes:
         (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
    }