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推送流程的更多相关文章

  1. ios 消息推送流程 转载

    iOS开发:推送通知简述及开发实践热度 1已有 706 次阅读 2013-10-15 09:23 |个人分类:经验之谈|系统分类:ios| IOS, 推送一.关于推送通知 推送通知,也被叫做远程通知, ...

  2. iOS APNs远程推送流程精简版

    1.去Apple Developer Center里创建应用的信息,指定APP ID(Bundle ID),配置里开启推送功能(Push Notifications). 后续步骤需要用到这个应用的包名 ...

  3. “iOS 推送通知”详解:从创建到设置到运行

    这是一篇编译的文章,内容均出自Parse.com的iOS开发教程,同时作者还提供了视频讲解.本文将带领开发者一步一步向着iOS推送通知的深处探寻,掌握如何配置iOS推送通知的奥义. 介绍一点点背景资料 ...

  4. iOS推送 再备

    这是一篇编译的文章,内容均出自Parse.com的iOS开发教程,同时作者还提供了视频讲解.本文将带领开发者一步一步向着iOS推送通知的深处探寻,掌握如何配置iOS推送通知的奥义. 介绍一点点背景资料 ...

  5. 一步一步教你做ios推送

    最近在研究ios的推送问题,遇到了一些问题,最终整理了一下.放在这里和大家分享 APNS的推送机制 首先我们看一下苹果官方给出的对ios推送机制的解释.如下图 Provider就是我们自己程序的后台服 ...

  6. iOS推送原理和证书生成简介

    1. 推送流程: Provider: 我们自己的后台服务器: APNS: 苹果的消息推送服务器 (1) 当Provider有消息要推送给手机的时候,先将消息和deviceToken等字段发送到APNS ...

  7. 手把手教你搞定个推iOS推送SDK集成

    以下是一位开发者在集成个推iOS推送SDK过程中的真实经历. 作者:Ezreallp 一次偶然的机会,公司的项目要用到推送,我自己本来就很懒,不愿意去弄整套APNS的流程,刚好之前跟朋友聊起过他们的产 ...

  8. iOS推送证书转pem文件

    iOS推送证书转 .pem文件. 推送证书转pem文件openssl x509 -in apns_miaobozhibo.cer -inform der -out apns_miaobozhibo.p ...

  9. IOS 推送-客户端处理推送消息

    IOS 推送-客户端处理推送消息 1.推送调用顺序 APN push的消息到达后,UIApplicationDelegate有两个方法和处理消息有关: 1)application:didReceive ...

随机推荐

  1. python学习笔记(基础四:模块初识、pyc和PyCodeObject是什么)

    一.模块初识(一) 模块,也叫库.库有标准库第三方库. 注意事项:文件名不能和导入的模块名相同 1. sys模块 import sys print(sys.path) #打印环境变量 print(sy ...

  2. 计算(LnN!)的值

    import java.util.*;import java.math.*;public class CaculatorLnN { public static void main(String[] a ...

  3. 如何数据库表数据导出到excel中

    1.首先须要有一个NPOI 2.接下来上代码 private void button1_Click(object sender, EventArgs e) { //1.通过Ado.net读取数据 st ...

  4. jquery瀑布流的制作

    首先,还是来看一下炫酷的页面: 今天就边做边说了: 一.准备工作 新建css,js,img文件夹存放相应文件,并在demo.html文件中引入外部文件(注意要把jquery文件引入),这里就不过多描述 ...

  5. 2D动画的制作

    通过css3的transform  transition可以实现平移,旋转,缩放,拉伸等效果 1.缩放 -webkit-transform: scale(1); -moz-transform: sca ...

  6. 【转】推荐10款最热门jQuery UI框架

    推荐10款最热门jQuery UI框架 原创 在进行Web开发时,并非所有的库都适合你的项目,但你仍需要收藏一些Web UI设计相关的库或框架,以在你需要的时候,加快你的开发效率.本文为你推荐10款非 ...

  7. View and Data API Tips: Hide elements in viewer completely

    By Daniel Du With View and Data API, you can hide some elements in viewer by calling "viewer.hi ...

  8. Android Stuido 常用快捷键

    Android Stuido 常用快捷键 Ctrl + Z : 撤消 Ctrl + G : 定位行 Ctrl + / : 单行注释 Ctrl + Shift + Z : 恢复 Ctrl + J : 快 ...

  9. Fresco从配置到使用(最高效的图片加载框架)

    Frescoj说明:      facebook开源的针对android应用的图片加载框架,高效和功能齐全. 支持加载网络,本地存储和资源图片: 提供三级缓存(二级memory和一级internal ...

  10. Java 反射 使用总结

    转载请标明出处:http://www.cnblogs.com/zhaoyanjun/p/6074887.html1 本文出自[赵彦军的博客] 反射机制是什么 反射机制是在运行状态中,对于任意一个类,都 ...