ios命令行发送推送

18 篇文章 0 订阅
6 篇文章 0 订阅

总结,到现在为止,我们已经生成:A:*.certSigningRequest文件(在步骤(4)中使用,用于生成证书B)、B:aps_developer_identity.cer证书(在Provider[Push服务器]服务端应用使用)、C:*..mobileprovision开发许可配置文件(在Client App客户端应用联机调试使用)。
3、新建一个项目
1. 创建一个"single view application" project,为省事,你设置的"Company Identifier" + "Production“必须和step 5创建的App ID的"bundle identifier"一致。2. 在AppDelegate.m file的"didFinishLaunchingWithOptions" method里,添加下列代码 (用于为app register push notification feature):// Let the device know we want to receive push notifications  [[UIApplication sharedApplication] registerForRemoteNotificationTypes:   (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];  
3. 在AppDelegate.m file里添加下列2个methods (用来handle register remote notification with device token和register error的events- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken  {      NSLog(@"My token is: %@", deviceToken);  }    - (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error  {      NSLog(@"Failed to get token, error: %@", error);  }  4. 运行该app in real device (simulator doesn't support push notification)。这时你会在device上看到一个popup window (该窗口只会出现一次,重装app不会再出现),提示你该app会send push notification给你,如果同意则clickOK,不同意则click "Now allow”。如果选择了OK,那么在"Setting > Notifications“里会有你的app在list里。而且这时你的Xcode output console会显示你的device token。
5: export "PushDemo" private key to a ".p12" file(该文件会在后面生成apns provider的.p12 or .pem file时用到)1). right click "PushDemo“ private key and select "Export ..."PushDemo2). Save the private key as “PushDemoKey.p12” file, click Save button3). 这时会让你输入2次用于加密该.p12 file的密码,例如用"123321",接着会要求你输入一次your mac account password
6: 在5中生成的“PushDemoKey.p12” file和step 6生成的"aps_development.cer" file是用于APNS provider side的源文件,APNS Provider side进行push message时要用到的"cert + key" file就是通过这2个file来生成。该Step就是用来生成for APNS provider side (php version)要用到这个"cert + key" pem file.1) open Terminal, go to Desktop (假设这2个file都在desktop里)2) 执行下列命令来生成和apns cer file对应的pem file "PushDemoCert.pem"openssl x509 -in aps_development.cer -inform der -out PushDemoCert.pem  
3) 执行下列命令来生成和private key .p12 file对应的pem file "PushDemoKey.pem" (注意:执行过程会要求你输入"PushDemoKey.p12"创建时设置的密码,以及设置"PushDemoKey.pem”的密码openssl pkcs12 -nocerts -out PushDemoKey.pem -in PushDemoKey.p12  
4) 执行下列命令把step 11.2生成的cert pem file和step 11.3生成的key pem file合成为一个pem file  "PushDemoCK.pem"
cat PushDemoCert.pem PushDemoKey.pem > PushDemoCK.pem  
7: 在5生成的“PushDemoKey.p12” file和step 6生成的"aps_development.cer" file是用于APNS provider side的源文件,该step是简单测试这2个file是否有效1) open Terminal, go to Desktop (假设这2个file都在desktop里)2) 执行下列命令来测试是否能够connect apple提供的不经加密(即不需使用任何证书!)的APNS server telnet gateway.sandbox.push.apple.com 2195  
如果你看到下列输出,则表示你的电脑可以connect APNS. 如果出现error,那么check你的firewall是否允许outgoing connections on port 2195。Trying 17.172.233.65...  Connected to gateway.sandbox.push-apple.com.akadns.net.  Escape character is '^]'.  Press Ctrl+C to close the connection.
3)  执行下列命令来测试是否能够connect apple提供的经加密(需使用2) and 3)生成的2个pem file!)的APNS "sandbox“ server for development.
openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert PushDemoCert.pem -key PushDemoKey.pem  
执行过程中会要你输入PushDemoKey.pem生成时设置的密码。如果connect server成功,就会等待你输入字串,你可以输入任意字串,然后回车,就会disconnect server。如果连接不成功,则openssl会显示错误信息。注意:实际上有2个APNS servers: the “sandbox” server (用于testing) the live server(用于production mode)。我们这里测试的是sandbox server。live apns server的操作类似。
8: 创建provider server side (php version)1). Download SimplePush PHP code to your mac machine and then unzip it.2). 去掉SimplePush folder里的pk.pem (它没用),把step 11.4生成的"PushDemoCK.pem" copy toSimplePush folder3). 修改simplepush.php file下面几行:// Put your device token here (without spaces)://device token来自Step 10的第4点,在output console获取,注意:要去掉前后的尖括号,和中间的所有空格
$deviceToken = '43fcc3cff12965bc45bf842bf9166fa60e8240c575d0aeb0bf395fb7ff86b465';
// Put your private key's passphrase here:
//该值是 3)生成PushDemoKey.pem时设置的密码
$passphrase = '123456';
// Put your alert message here:
$message = 'My first push notification!';
//.....stream_context_set_option($ctx, 'ssl', 'local_cert', 'PushDemoCK.pem');4). 在terminal window里,go to the simplepush folder,然后执行下列命令,你的iPhone应该会收到一条push message。php simplepush.php  
注意:如果你的app在iphone里是正在运行,而且app是在front end时,当它收到push message时是不会出现在iPhone顶部的notification area的!
 http://www.cnblogs.com/cdts_change/p/3240893.html
参考文章:http://mmz06.blog.163.com/blog/static/121416962011111710934946/
     http://user.qzone.qq.com/75869071/infocenter%23!app=2& via=QZ.HashRefresh&pos=1351564081#!app=2&via=QZ.HashRefresh&pos=1351564081 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值