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

查看:19
本文介绍了推送通知未在 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);

我还为推送通知配置了应用程序.配置推送后,我还重新创建配置文件,旧的删除一个,安装新的配置文件.我运行应用程序,它为我提供了设备 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天全站免登陆