推送通知未在iphone上接收 [英] Push notification not receiving on iphone

查看:192
本文介绍了推送通知未在iphone上接收的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 本教程 学习推送通知。

I am using this tutorial to learn push notification.

<?php

// Put your device token here (without spaces):
$deviceToken = '1675ba8bb005740bb514222227f861c30230a81e6eed6bb6b8f353c57831341d';

// Put your private key's passphrase here:
$passphrase = '111134';

// Put your alert message here:
$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);

// 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);

 echo 'Connected to APNS' . PHP_EOL;

// Create the payload body
$body['aps'] = array(
'alert' => $message,
'sound' => '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));
 echo 'result =' . $result. PHP_EOL;
if (!$result)
echo 'Message not delivered' . PHP_EOL;
else
echo 'Message successfully delivered' . PHP_EOL;

 // Close the connection to the server
fclose($fp);

我还为推送通知配置app。配置推送后,我还重新创建配置文件,旧删除一个,安装新的配置文件。
我运行应用程序它给我设备ID然后我连接服务器沙箱和生产发送推送通知与他们的相对推送配置文件但仍然我无法在我的设备上接收推送通知。

I also configure app for push notification. After configuring for push i also recreate provisioning profiles, old delete one, install new profile. I run app it gives me device id and then i connect both server sandbox and production to send push notification with their relative push profiles but still i am not able to receive push notification on my device.

我还在我的设备上安装ipusher并检查推送通知。他们来自那个应用程序。

I also install ipusher on my device and check push notification. they are coming from that application.

我注意到一个奇怪的事情是我更改了我的应用程序标识符并使​​用任何其他应用程序ID然后设备令牌保持不变

One strange thing i notice is that i change my application identifier and use any other app id then device token remain same

现在我的问题是我没有在我的设备上收到推送通知。

Now my problem is I am not receiving the push notification on my device.

问题不在我的个人资料中。可能是错误是我正在使用的PHP代码,因为当我在远程服务器上使用简单的apns然后它发送推送通知。
收到的通知时间为6到7个小时。我认为这是由于设备端的网络问题。
但是现在它在生产配置文件2天后工作正常。现在通知很快就可以在我的设备上发送,但在某些设备上需要30秒到5分钟。

The problem is not in my profiles. May be the error is php code that i am using because when i use the easy apns on remote server then it sends push notifications. The notifications received time was 6 to 7 hours. I think this is due to network problem on my device side. But now it is working fine after 2 days on production profile. Now notification take no time for delivering on my device but it is taking 30 sec to 5 minutes on some devices.

那里如果您没有从其他应用程序接收设备上的推送通知,则可能是另一个问题,那么您应该检查DNS以获取连接。

There can be one more problem if you are not receiving push notifications on your device from other apps too, then you should check your DNS for the connection.

推荐答案

好吧我终于得到了我的问题。问题不在于代码实际上问题出在我的iphone中设置错误的DNS值。 Iphone自动将我的路由器的ip放入DNS字段。现在我给我的服务提供商的DNS值,然后它工作正常。现在我收到推送消息后立即发送。

Okay i finally got my Problem. The problem is not in code actually the problem is in Wrong DNS Value set in my iphone. Iphone automatically place ip of my router for DNS field. Now i give the DNS value of my service provider then it works fine. Now I am receiving Push messages As soon as i sent them.

我希望它可以帮助其他人。

这篇关于推送通知未在iphone上接收的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆