成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

iPhone 搭建PHP版Push服務器 實例操作

移動開發 iOS
本文介紹的是iPhone 搭建PHP版Push服務器 實例操作,很詳細的操作步驟,我們先來看內容。

iPhone 搭建PHPPush服務器 實例操作是本文介紹的內容。在應用里加入 Push 功能對于用戶及時獲取信息是非常有幫助的,以前介紹過 iPhone Push (推送通知)功能原理淺析,里面提到要為自己的 App 添加推送功能,開發者先要搭建一個推送服務器。下面就介紹一個為 iPhone 應用搭建 php push 服務器的流程。

0.在Mac OS X機器上安裝好XCode, 連接一臺正常的iPhone, 保持平和的心態

APP 開發基礎設置

1.在iPhone Provisioning Portal中建立好APP ID和Device.

2. 在Keychain Access.app中生成證書請求CertificateSigningRequest.certSigningRequest(菜單 > Keychain Access > Certificate Assistant > Request a Certificate From a Certificate Authority...).

3.在iPhone Provisioning Portal > Certificates中請求一個證書(點擊Request Certificate,上傳CertificateSigningRequest.certSigningRequest).

4.請求完成后,將證書文件(developer_identity.cer)下載,雙擊導入到Key Chain中.

5.在iPhone Provisioning Portal > Provisioning 中,新建一個Profile, 選擇指定的APP ID和 Devices后生成.

6.將剛剛生成的Profile下載為*_profile.mobileprovision, 雙擊該文件, 將profile加載到iPhone中.

Push Notification service設置

7.在iPhone Provisioning Portal > App IDs,選擇需要Push服務的App ID, 進入Configure.

8.確認 Enable for Apple Push Notification service ,配置 Development Push SSL Certificate, 上傳第2步生成的證書請求.

9.下載生成的aps_developer_identity.cer, 完成Push服務配置.

10.雙擊aps_developer_identity.cer,保存到Key Chain.

生成php Push Notification sender需要的證書文件

11.在Keychain Access.app里選定這個新證書(Apple Development Push Services*),導出到桌面,保存為Certificates.p12.

12.運行如下命令:

  1. openssl pkcs12 -clcerts -nokeys -out cert.pem -in Certificates.p12  
  2. openssl pkcs12 -nocerts -out key.pem -in Certificates.p12  
  3. openssl rsa -in key.pem -out key.unencrypted.pem  
  4. cat cert.pem key.unencrypted.pem > ck.pem 

獲得php Push Notification sender所需的設備令牌:

13.新建一個View-based Application項目,在$PROJECT_NAMEAppDelegate.m中:

a.粘貼如下代碼:

  1.  - (void)applicationDidFinishLaunching:(UIApplication *)app {  
  2.      // other setup tasks here….  
  3.     [window addSubview:viewController.view];  
  4.      [self alertNotice:@"" withMSG:@"Initiating Remote Noticationss Are Active" cancleButtonTitle:@"Ok" otherButtonTitle:@""];  
  5.     [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
  6. (UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound)];  
  7.  }  
  8.  - (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {  
  9.      //NSLog(@"devToken=%@",deviceToken);  
  10.      [self alertNotice:@"" withMSG:[NSString stringWithFormat:@"devToken=%@",deviceToken] cancleButtonTitle:@"Ok" otherButtonTitle:@""];  
  11.  }  
  12.  - (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {  
  13.     NSLog(@"Error in registration. Error: %@", err);  
  14.      [self alertNotice:@"" withMSG:[NSString stringWithFormat:@"Error in registration. Error: %@", err]
  15.  cancleButtonTitle:@"Ok" otherButtonTitle:@""];  
  16.  }  
  17. . -(void)alertNotice:(NSString *)title withMSG:(NSString *)msg cancleButtonTitle:(NSString *)cancleTitle 
  18. otherButtonTitle:(NSString *)otherTitle{  
  19.      UIAlertView *alert;  
  20.     if([otherTitle isEqualToString:@""])  
  21.          alert = [[UIAlertView alloc] initWithTitle:title message:msg delegate:self cancelButtonTitle:cancleTitle otherButtonTitles:nil,nil];  
  22.      else  
  23.          alert = [[UIAlertView alloc] initWithTitle:title message:msg delegate:self cancelButtonTitle:cancleTitle 
  24. otherButtonTitles:otherTitle,nil];  
  25.      [alert show];  
  26.      [alert release];  
  27.  } 

b.在 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 方法中增加

  1. [self alertNotice:@"" withMSG:@"Initiating Remote Noticationss Are Active" cancleButtonTitle:@"Ok" otherButtonTitle:@""];  
  2. [[UIApplication sharedApplication] registerForRemoteNotificationTypes:  
  3.  
  4.        (UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound)]; 

14.項目設置

a.Targets > $APP_NAME > context menu > Properties > Identifier

修改

  1. identifier  
  2.  為  
  3. App ID  
  4. b.Targets > $APP_NAME > context menu > Build > Code Signing > Code Signing Identifier > Any iPhone OS Device 

指定 iPhone Developer 為開發用機,編譯并運行后會在iPhone上顯示設備令牌

php Push Notification sender代碼如下:

  1. <?php 
  2. deviceToken = "設備令牌";   
  3. $body = array("aps" => array("alert" => 'message', "badge" => 1, "sound" => 'received5.caf'));  
  4. $ctx = stream_context_create();  
  5. stream_context_set_option($ctx, "ssl", "local_cert", "ck.pem");   
  6. $fp = stream_socket_client("ssl://gateway.sandbox.push.apple.com:2195", $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);  
  7. if (!$fp) {  
  8.     print "Failed to connect $err $errstrn";  
  9.     return;  
  10. }  
  11. print "Connection OK\n";  
  12. payload = json_encode($body);  
  13. $msg = chr(0) . pack("n",32) . pack("H*", $deviceToken) . pack("n",strlen($payload)) . $payload;  
  14. rint "sending message :" . $payload . "\n";  
  15. fwrite($fp, $msg);  
  16. fclose($fp);  
  17. ?> 

小結:iPhone 搭建PHPPush服務器 實例操作的內容介紹完了,希望本文對你有幫助。

責任編輯:zhaolei 來源: 互聯網
相關推薦

2011-07-26 16:43:59

iPhone Web 服務器

2011-07-27 14:37:33

iPhone Push Notif 服務器

2012-09-21 10:36:54

PHPPHP搭建Web

2010-05-27 16:41:38

MySQL服務器

2011-04-22 10:36:09

Server Push推送技術

2016-10-13 15:57:28

nginxphpwindows

2010-10-19 09:35:08

Ubuntu 10.1云環境

2011-07-18 13:37:53

2014-08-06 11:25:00

LinuxSVN服務器

2021-09-10 10:07:17

Nginx虛擬主機服務器

2012-09-19 09:47:58

PHPWeb服務器

2018-11-12 11:09:24

2010-08-26 11:01:05

DHCP服務器

2011-09-07 10:44:36

DHCP服務器配置

2010-08-05 13:56:06

路由器配置

2009-12-10 17:20:00

PHP服務器架設

2010-08-29 20:53:03

DHCP服務器

2016-10-11 12:45:50

PythonWeb服務器

2009-11-30 11:33:50

sendmail服務器

2018-11-22 09:40:11

Docker服務器企業版
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 久久久久久久久久久久久久久久久久久久 | 精品国产乱码久久久久久闺蜜 | 亚洲精品丝袜日韩 | 欧美成人综合 | 一区在线观看 | 成在线人视频免费视频 | 久久小视频 | 久久久久九九九九 | 久久久久久久91 | 一本岛道一二三不卡区 | 人成在线视频 | 久久久久久久一区二区 | 激情五月婷婷丁香 | 看片地址 | 91国产精品 | 在线电影日韩 | 国产馆 | h网站在线观看 | 国产视频1 | 亚洲精品电影网在线观看 | 久久av一区二区三区 | 欧美一区二区三区视频 | 欧美午夜精品久久久久久浪潮 | www.youjizz.com日韩 | 91新视频 | 亚洲小视频| 国际精品鲁一鲁一区二区小说 | 欧美日韩综合视频 | 亚洲一区在线日韩在线深爱 | 五月天国产 | 中文在线一区二区 | 观看av | av免费看在线 | 国产成人精品免高潮在线观看 | 久草综合在线视频 | 国产一区二区激情视频 | 成人一级毛片 | 日韩免费一区二区 | 中文字幕日韩欧美 | 国产日韩一区 | 爱爱视频网 |