为 iPhone 应用搭建 php 版 push 服务器的流程
2010-08-26 11:20:00 来源:WEB开发网23. }
b.在 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 方法中增加
1. [self alertNotice:@"" withMSG:@"Initiating Remote Noticationss Are Active" cancleButtonTitle:@"Ok" otherButtonTitle:@""];
2. [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound)];
14.项目设置
a.Targets > $APP_NAME > context menu > Properties > Identifier
修改 identifier 为App ID
b.Targets > $APP_NAME > context menu > Build > Code Signing > Code Signing Identifier > Any iPhone OS Device
指定 iPhone Developer 为开发用机
15.编译并运行后会在iPhone上显示设备令牌
16.php Push Notification sender代码如下:
1. < ?php
2. $deviceToken = "设备令牌";
3.
4. $body = array("aps" => array("alert" => 'message', "badge" => 1, "sound" => 'received5.caf'));
5.
6. $ctx = stream_context_create();
7. stream_context_set_option($ctx, "ssl", "local_cert", "ck.pem");
8.
9. $fp = stream_socket_client("ssl://gateway.sandbox.push.apple.com:2195", $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
10. if (!$fp) {
11. print "Failed to connect $err $errstrn";
12. return;
13. }
14. print "Connection OK ";
15. $payload = json_encode($body);
16. $msg = chr(0) . pack("n",32) . pack("H*", $deviceToken) . pack("n",strlen($payload)) . $payload;
17. print "sending message :" . $payload . " ";
18. fwrite($fp, $msg);
19. fclose($fp);
20. ?>
- ››搭建windows2003 ntp服务器
- ››iphone图片拉伸的几种方法
- ››iphone正则表达式的简单使用
- ››iPhone开发Unresolved Symbols CAKeyframeAnimati...
- ››IPhone开发-“此证书是由未知颁发机构签名”解决方...
- ››IPhone开发-整合私钥和证书,生成.p12文件
- ››iPhone应用开发-UIPickerView选取器详解
- ››iphone 获取屏幕的宽度和高度
- ››iPhone读取工程包中的二进制文件
- ››iPhone新手机 不挂YouTube APP
- ››iPhone 获取指定格式的时间和日期
- ››iPhone版PPS走进生活 观赏体验媲美PC版
更多精彩
赞助商链接