在SAE使用Apple Push Notification Service服务开发iOS应用
来源:互联网 发布:重庆市知行卫校 编辑:程序博客网 时间:2024/06/07 11:59
1,在iOS开发者中心: iOS ProvisioningPortal 创建一个AppID,如图:
2,生成iOS Push Service证书,如图:
按照上述提示操作:
回到网站,
选择刚才生成的文件,并上传:
点击“Download”下载iOS Push Service证书文件
3,导入证书文件到keychain:双击即可
4,生成ck.pem
导出cert.p12
导出key.p12:
得到这样两个文件:
接下来打开终端:
输入命令:openssl pkcs12 -clcerts -nokeys -out cert.pem -incert.p12
然后输入命令:openssl pkcs12 -nocerts -out key.pem-in key.p12
最后合并成一个ck.pem文件:
输入命令:cat cert.pem key.pem > ck.pem
得到一个ck.pem文件:
5, 生成并安装Profile文件:
6, 上传ck.pem到SAE,如图
7, 客户端程序:
设置profile:
在info.plist中设置Bundleidentifier:
将app注册notification里面, 并从APNS上获取测试机的deviceToken, 代码如下:
- (BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOp
{
UIRemoteNotificationType
UIRemoteNotificationType
}
#pragma mark -
#pragma mark APNS
- (void)application:(UIApplication *)applicationdidRegisterForRemoteNoti
NSLog(@"uniqueIdentifier: %@", [[UIDevice currentDevice]uniqueIdentifier]);
}
- (void)application:(UIApplication *)applicationdidFailToRegisterForRemo
}
- (void)application:(UIApplication *)applicationdidReceiveRemoteNotifica
}
8, 服务器端程序:
<?php
include_once("saeapns.class.php");
//许可证id
$cert_id = 1;
//设备令牌
$device_token = "xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxxxxxxxxxx xxxxxxxx xxxxxxxx";
$message = "测试消息 from SAE: " . date('Y-m-d H:i:s');
//消息体,格式详见iOS官方文档
$body = array(
'aps' => array('alert' => $message, 'badge' => 1, 'sound' =>'in.caf')
);
$apns = new SaeAPNS();
$result = $apns->push($cert_id , $body ,$device_token);
if ($result != false) {
echo '发送成功';
} else {
echo '发送失败';
var_dump($apns->errno(),$apns->errmsg());
}
?>
9, 手机收到通知效果:
实例代码下载地址:
http://vdisk.weibo.com/s/SbY2
- 在SAE使用Apple Push Notification Service服务开发iOS应用, 实现消息推送
- 在SAE使用Apple Push Notification Service服务开发iOS应用
- 在SAE使用Apple Push Notification Service服务开发iOS应用, 实现消息推送
- iOS-在SAE使用Apple Push Notification Service实现消息推送
- IOS 推送服务--Apple Push Notification Service
- IOS iphone 推送服务--Apple Push Notification Service
- 【IPhone开发】 iphone 推送服务--Apple Push Notification Service
- iphone 推送服务--Apple Push Notification Service
- iphone 推送服务--Apple Push Notification Service
- iphone 推送服务--Apple Push Notification Service
- iphone 推送服务--Apple Push Notification Service
- iphone 推送服务--Apple Push Notification Service
- iphone 推送服务--Apple Push Notification Service
- iphone 推送服务--Apple Push Notification Service .
- iphone 推送服务--Apple Push Notification Service
- 生成Apple Push Notification Service服务证书
- iphone 推送服务--Apple Push Notification Service
- iphone 推送服务--Apple Push Notification Service
- C# 文件操作小结
- 《微软Silverlight简介》
- Activity not started, its current task has been brought to the front
- git删除错误提交的commit
- Google Chrome(谷歌浏览器)修改网页背景颜色的办法(比如修改为护眼的豆沙绿)
- 在SAE使用Apple Push Notification Service服务开发iOS应用
- 浅谈单片机c语言模块化编程-附ds1302时钟芯片驱动程序
- 驻韩大使就中国渔民死亡事件今上午约见韩方-驻韩大使-约见-渔民死亡
- 设计模式示例-原型模式
- Struts2与Spring3整合遇到Action not found问题的解决
- linux下,纯c++使用libxml2读取xml文件
- 修改phpmyadmin中的登陆超时时间
- 基于HTML5构建Web操作系统
- C++符号常量-预处理器方式(修改基本和符合常量的最大和最小值)