IOS Remote Notification
1. 本地证书合成
rm *.pem
echo "export cert..."
openssl pkcs12 -clcerts -nokeys -out push_cert.pem -in push_cert.p12
echo "export key..."
openssl pkcs12 -nocerts -out push_key.pem -in push_key.p12
openssl rsa -in push_key.pem -out push_key_noenc.pem
echo "combine together"
cat push_cert.pem push_key_noenc.pem > apns-dev.pem
echo "done"
其中push_cert.p12和push_key.p12分别是中keychain中根据开发证书导出来的证书和私钥。
上述脚本最终会导出一个名称为“apns-dev.pem”的认证文件。
下面会使用这个认证文件进行sanbox推送
2. 沙盒推送
<?php
$deviceToken= '86441e1421a239d0f7eed26ab4c8bd9a9ccec21b';
$body = array("aps" => array("alert" => 'message', "badge" => 2, "sound"=>'default'));
$ctx = stream_context_create();
stream_context_set_option($ctx,"ssl","local_cert","apns-dev.pem");
$pass = "aabb11";
stream_context_set_option($ctx, 'ssl', 'passphrase', $pass); //$fp = stream_socket_client("ssl://gateway.push.apple.com:2195", $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx); // for real push service
$fp = stream_socket_client("ssl://gateway.sandbox.push.apple.com:2195", $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx); //for sandbox if (!$fp)
{
echo "Failed to connect $err $errstrn";
return;
}
print "Connection OK\n";
$payload = json_encode($body);$msg = chr(0) . pack("n",32) . pack("H*", str_replace(' ', '', $deviceToken)) . pack("n",strlen($payload)) . $payload;
echo "sending message :" . $payload ."\n";
fwrite($fp, $msg);
fclose($fp);
?>
其中deviceToken是苹果手机的40位的UDID。
这是实习的时候学到的,但是最终这个方案没有测试成功:
问题是:
php pushtest.php
Warning: stream_socket_client(): Failed to enable crypto in pushtest.php on line 10
Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in pushtest.php on line 10
真的非常遗憾,希望以后还有机会学习IOS方面的内容!
IOS Remote Notification的更多相关文章
- iOS 远程通知(Remote Notification)和本地通知(Local Notification)
ios通知分为远程通知和本地通知,远程通知需要连接网络,本地通知是不需要的,不管用户是打开应用还是关闭应用,我们的通知都会发出,并被客户端收到 我们使用远程通知主要是随时更新最新的数据给用户,使用本地 ...
- iOS开发笔记8:Remote Notification远程消息推送处理
远程消息推送处理场景有三种:分别是app还没有运行.app在前台运行以及app在后台运行,下面介绍相关流程及三种场景下处理步骤 1.流程 (1)注册通知 首先是在注册远程消息推送,需要注意的是iOS8 ...
- iOS remote debug & Android remote debug & Chrome & APP
iOS remote debug & Android remote debug & Chrome & APP iOS remote debugging 如何在 iOS 真机上调 ...
- Android/iOS Remote debugging
简单介绍 使用下面方法可以定位webview中的元素,无法定位view中的元素. 原文地址:http://mp.weixin.qq.com/s/y_UfdgjT_pkKgYivJmqt7Q webvi ...
- ios的notification机制是同步的还是异步的
与javascript中的事件机制不同.ios里的事件广播机制是同步的,默认情况下.广播一个通知,会堵塞后面的代码: -(void) clicked { NSNotificationCenter *c ...
- Android 与 iOS 推送 Push Notification 的区别
Android 安卓使用 GCM (Google Cloud Messaging) 接收推送,然后应用根据实际情况决定做什么反应,比如显示一个 Notification. 所以安卓下,推送 Push ...
- iOS web remote debug 正确的姿势
在使用iOS Remote debug需要做以下准备 1. iOS devices 开启java script and web inspector 开启方式如下: 2. mac OS 自带的Safar ...
- [转载]iOS 10 UserNotifications 框架解析
活久见的重构 - iOS 10 UserNotifications 框架解析 TL;DR iOS 10 中以前杂乱的和通知相关的 API 都被统一了,现在开发者可以使用独立的 UserNotifica ...
- iOS 10、Xcode 8 遇到部分问题解决记录
今天把iphone 6 升级到ios10 后,用Xcode 7进行真机调试的时候提示: Could not find Developer Disk Image 果断准备升级到Xcode 8 .但是想保 ...
随机推荐
- BZOJ 1571: [Usaco2009 Open]滑雪课Ski
Description Farmer John 想要带着 Bessie 一起在科罗拉多州一起滑雪.很不幸,Bessie滑雪技术并不精湛. Bessie了解到,在滑雪场里,每天会提供S(0<=S& ...
- 标准MD5加密算法
标准MD5加密算法: public class Md5 { public static String getMd5(String s) { char hexDigits[] = { '0', '1', ...
- Best Practices for Using Alpha
Alpha是图形界面开发中常用的特效,通常我们会使用以下代码来实现Alpha特效: view.setAlpha(0.5f); View.ALPHA.set(view, 0.5f); ObjectAni ...
- 使用ListView时遇到的问题
这周练习ListView时遇到了一个问题,从数据库中查询出的数据绑定到LIstView上,长按某个item进行删除操作,每次点击item取得的id都不对,调了半天终于找到了原因,关键是自己对自定义的B ...
- 【转】Android bluetooth介绍(三): 蓝牙扫描(scan)设备分析
原文网址:http://blog.csdn.net/xubin341719/article/details/38584469 关键词:蓝牙blueZ A2DP.SINK.sink_connect.s ...
- C#后台执行bat
C#后台执行bat ProcessStartInfo p = new ProcessStartInfo(); p.FileName = "C:\\1.bat"; p.WindowS ...
- HDU-1686 Oulipo
学习:重点理解这句话的意思: next[j]会告诉我们从哪里开始匹配 模板题. Oulipo Time Limit: 3000/1000 MS (Java/Others) Memory ...
- Android webView 正确的用法
Android webView 正确的用法 引言: 我在网络找了几个例子,基本上都有问题,<Android疯狂讲义>13.4中的源代码也有问题.终于在官网找到正确的用法.点我. 基本用法: ...
- [ZETCODE]wxWidgets教程二:辅助类
本教程原文链接:http://zetcode.com/gui/wxwidgets/helperclasses/ 翻译:瓶哥 日期:2013年11月27日星期三 邮箱:414236069@qq.com ...
- 支持Python 2.7的pylot
想用pylot测试一下板子上面的嵌入式web server.结果报错. E:\pylot_1.26>run.py -a 2 Traceback (most recent call last): ...