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 1612: [Usaco2008 Jan]Cow Contest奶牛的比赛
Description FJ的N(1 <= N <= 100)头奶牛们最近参加了场程序设计竞赛:).在赛场上,奶牛们按1..N依次编号.每头奶牛的编程能力不尽相同,并且没有哪两头奶牛的水平 ...
- Android-x86虚拟机安装配置全攻略
转自Android-x86虚拟机安装配置全攻略 注:这里安装从简,具体请参考虚拟机Vmware安装运行安卓4.0详细教程 Android-x86虚拟机安装配置网上有很多,但是全部说明白的确不多,希望这 ...
- Web-Scale IT 我之见!
Gartner 曾在发表过的一篇文章中表示,到2017年,全球50%的企业将使用Web-Scale IT 架构.下面我们来看看 Andre Leibovici 对 Web-Scale IT 的看法: ...
- POJ 1286 Necklace of Beads(Polya定理)
点我看题目 题意 :给你3个颜色的n个珠子,能组成多少不同形式的项链. 思路 :这个题分类就是polya定理,这个定理看起来真的是很麻烦啊T_T.......看了有个人写的不错: Polya定理: ( ...
- 【UVA 1411】 Ants (KM)
Young naturalist Bill studies ants in school. His ants feed onplant-louses that live on apple trees. ...
- 【HDU 5456】 Matches Puzzle Game (数位DP)
Matches Puzzle Game Problem Description As an exciting puzzle game for kids and girlfriends, the Mat ...
- Xamarin 开发常见问题
原文:Xamarin 开发常见问题 Verify the project is selected to be deployed in the Solution Configuration Manage ...
- Android开源项目发现---ViewPager 、Gallery 篇(持续更新)
1. Android-ViewPagerIndicator 鼎鼎大名,配合ViewPager使用的Indicator,支持各种位置和样式 项目地址:https://github.com/JakeWh ...
- laravel 框架学习资料
demo:http://forumsarchive.laravel.io/viewtopic.php?id=3536 使用Laravel和Angular创建一个单页的评论应用 http://devel ...
- hdu4435 charge-station(先建后拆+bfs)
charge-station Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...