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 2251: [2010Beijing Wc]外星联络 后缀数组
2251: [2010Beijing Wc]外星联络 Time Limit: 30 Sec Memory Limit: 256 MBSubmit: 424 Solved: 232[Submit][ ...
- OSAL多任务资源分配机制
转自OSAL多任务资源分配机制 一.概述 OSAL (Operating System Abstraction Layer),翻译为"操作系统抽象层". 个应用程序对象. ...
- ANDROID_MARS学习笔记_S05_002_给传感器注册listener
1 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); se ...
- 嵌入式C语言之---模块化编程
当你在一个项目小组做一个相对较复杂的工程时,意味着你不再独自单干.你需要和你的小组成员分工合作,一起完成项目,这就要求小组成员各自负责一部分工程.比如你可能只是负责通讯或者显示这一块.这个时候,你就应 ...
- 使用ListView时遇到的问题
这周练习ListView时遇到了一个问题,从数据库中查询出的数据绑定到LIstView上,长按某个item进行删除操作,每次点击item取得的id都不对,调了半天终于找到了原因,关键是自己对自定义的B ...
- 抽象工厂模式[wiki]
抽象工厂[编辑] 维基百科,自由的百科全书 跳转至: 导航. 搜索 以统一塑模语言中的类型图来表示抽象工厂 抽象工厂模式(英语:Abstract factory pattern)是一种 ...
- 【HDOJ】3068 最长回文
马拉车算法O(n)可解. /* 3068 */ #include <iostream> #include <string> #include <map> #incl ...
- Total Commander快捷键
(1)tab键---切换左.右两个大的窗口:
- windows下面配置jdk环境变量
在环境变量中添加如下: Path D:\Program Files\Java\jdk1.6.0_26\binJAVA_HOME D:\Program Files\Java\jdk1.6.0_26CLA ...
- Linux学习笔记31——网络信息
一 主机数据库函数 #include <netdb.h> struct hostent *gethostbyaddr(const void *addr, //地址 size_t len, ...