iOS推送流程
1. 在apple开发者帐号上创建一个BundleID,创建证书或者Xcode上都是用这个BundleID(例如com.mycompany.pushDemo)
2. 代码层面:
在capability里面将pushNotification设置为ON。
在Appdelegate里面的didfinishLaunching。。。添加代码
//推送Notification
if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
{
UIUserNotificationSettings *notiSettings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIRemoteNotificationTypeSound) categories:nil];
[application registerUserNotificationSettings:notiSettings];
} else{ // ios7
[application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound |UIRemoteNotificationTypeAlert)];
}
[application registerForRemoteNotifications];
再添加回调函数
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)pToken{
const unsigned char *pBytes = pToken.bytes;
NSMutableString *strToken = [[NSMutableString alloc]init];
for (int iloop = 0; iloop < pToken.length; iloop++) {
[strToken stringByAppendingFormat:@"%02x",pBytes[iloop]];
}
NSLog(@"token is : %@",[strToken copy]);
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
NSLog(@"userInfo == %@",userInfo);
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{
NSLog(@"Regist fail%@",error);
}
3. 在“钥匙串访问”-》“证书助理”-》“从证书颁发机构请求证书” 将其保存到磁盘为CertificateSigningRequest.certSigningRequest
4. 在官网appid中edit中,勾选上PushNotification,然后在下一步中点击“create certificate”,选择上面的CertificateSigningRequest.certSigningRequest文件。生成一个aps_dev.cer
5. 双击aps_dev.cer,此时要是串会多处一个证书,将这个证书保存为*.p12文件。
6. 命令行中: openssl pkcs12 -in push_dev.p12 -out push_dev.pem -nodes
这个push_dev.pem就是关键的文件。
通过php脚本运行,就可以发送了。
- <?php
- // ??????????deviceToken???????????????
- $deviceToken = '????????';
- // Put your private key's passphrase here:
- $passphrase = '*****';
- // Put your alert message here:
- $message = 'My first push test!';
- ////////////////////////////////////////////////////////////////////////////////
- $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.push.apple.com:2195?, $err, $errstr, 60, //STREAM_CLIENT_CONNECT, $ctx);
- //?????????????appstore??????
- $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));
- if (!$result)
- echo 'Message not delivered' . PHP_EOL;
- else
- echo 'Message successfully delivered' . PHP_EOL;
- // Close the connection to the server
- fclose($fp);
- ?>
iOS推送流程的更多相关文章
- ios 消息推送流程 转载
iOS开发:推送通知简述及开发实践热度 1已有 706 次阅读 2013-10-15 09:23 |个人分类:经验之谈|系统分类:ios| IOS, 推送一.关于推送通知 推送通知,也被叫做远程通知, ...
- iOS APNs远程推送流程精简版
1.去Apple Developer Center里创建应用的信息,指定APP ID(Bundle ID),配置里开启推送功能(Push Notifications). 后续步骤需要用到这个应用的包名 ...
- “iOS 推送通知”详解:从创建到设置到运行
这是一篇编译的文章,内容均出自Parse.com的iOS开发教程,同时作者还提供了视频讲解.本文将带领开发者一步一步向着iOS推送通知的深处探寻,掌握如何配置iOS推送通知的奥义. 介绍一点点背景资料 ...
- iOS推送 再备
这是一篇编译的文章,内容均出自Parse.com的iOS开发教程,同时作者还提供了视频讲解.本文将带领开发者一步一步向着iOS推送通知的深处探寻,掌握如何配置iOS推送通知的奥义. 介绍一点点背景资料 ...
- 一步一步教你做ios推送
最近在研究ios的推送问题,遇到了一些问题,最终整理了一下.放在这里和大家分享 APNS的推送机制 首先我们看一下苹果官方给出的对ios推送机制的解释.如下图 Provider就是我们自己程序的后台服 ...
- iOS推送原理和证书生成简介
1. 推送流程: Provider: 我们自己的后台服务器: APNS: 苹果的消息推送服务器 (1) 当Provider有消息要推送给手机的时候,先将消息和deviceToken等字段发送到APNS ...
- 手把手教你搞定个推iOS推送SDK集成
以下是一位开发者在集成个推iOS推送SDK过程中的真实经历. 作者:Ezreallp 一次偶然的机会,公司的项目要用到推送,我自己本来就很懒,不愿意去弄整套APNS的流程,刚好之前跟朋友聊起过他们的产 ...
- iOS推送证书转pem文件
iOS推送证书转 .pem文件. 推送证书转pem文件openssl x509 -in apns_miaobozhibo.cer -inform der -out apns_miaobozhibo.p ...
- IOS 推送-客户端处理推送消息
IOS 推送-客户端处理推送消息 1.推送调用顺序 APN push的消息到达后,UIApplicationDelegate有两个方法和处理消息有关: 1)application:didReceive ...
随机推荐
- ASP.NET Core File Providers
原文地址:FileProvider By Steve Smith ASP.NET Core通过对File Providers的使用实现了对文件系统访问的抽象. 查看或下载示例代码 File Provi ...
- Debug JDK变量显形
本文面向的朋友 本文主要说明在使用Eclipse Debug JDK时,看不到变量值的解决办法. 如果您看到上面绿色字体表示不敢兴趣,请一定果断back,如果您不爽,请在下面使劲的拍. Debug J ...
- 两种常用的C语言排序算法
1. 要求输入10个整数,从大到小排序输出 输入:2 0 3 -4 8 9 5 1 7 6 输出:9 8 7 6 5 3 2 1 0 -4 解决方法:选择排序法 实现代码如下: #include &l ...
- 如何在web中实现类似excel的表格控件
Execl功能非常强大,内置的很多函数或公式可以大大提高对数据的加工处理能力.那么在web中有没有类似的控件呢?经过一番搜寻,发现handsontable具备了基本的excel功能支持公式,同时能对数 ...
- jsonp跨域请求
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 软件工程第二次作业——git的使用
1. 参照 http://www.cnblogs.com/xinz/p/3803109.html 的第一题,每人建立一个GitHub账号,组长建立一个Project,将本组成员纳入此Porject中的 ...
- 利用SQL Server 2008 R2创建自动备份计划
本文主要利用SQL Server 2008 R2自带的"维护计划"创建一个自动备份数据的任务. 首先,启动 Sql Management studio,确保"SQL Se ...
- 织梦DedeCMS模板防盗的四种方法
织梦(DedeCMS)模板也是一种财富,不想自己辛辛苦苦做的模板被盗用,在互联网上出现一些和自己一模一样的网站,就需要做好模板防盗.本文是No牛收集整理自网络,不过网上的版本都没有提供 Nginx 3 ...
- [Hadoop in Action] 第1章 Hadoop简介
编写可扩展.分布式的数据密集型程序和基础知识 理解Hadoop和MapReduce 编写和运行一个基本的MapReduce程序 1.什么是Hadoop Hadoop是一个开源的框架,可编写和运 ...
- MySQL学习笔记
数据库 P3306create database [if not exists] db_name [characterset gbk];use database;//跳转数据库show databas ...