WEB开发网
开发学院手机开发iPhone 开发 为 iPhone 应用搭建 php 版 push 服务器的流程 阅读

为 iPhone 应用搭建 php 版 push 服务器的流程

 2010-08-26 11:20:00 来源:WEB开发网   
核心提示:23. }b.在 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 方法中增加1. [self alertNotice:@""

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. ?>

上一页  1 2 3 

Tags:iPhone 应用 搭建

编辑录入:coldstar [复制链接] [打 印]
赞助商链接