码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 远程推送参考资料及自己遇到的问题

时间:2014-12-25 14:40:25      阅读:358      评论:0      收藏:0      [点我收藏+]

标签:

很好的参考资料:http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1

中文的参考资料: 第一部分 http://www.tairan.com/archives/194    

第二部分:http://www.tairan.com/archives/281 

第三部分:http://www.tairan.com/archives/240


另外还有cocoa上资料:http://www.cocoachina.com/bbs/read.php?tid-98797-keyword-%D4%B6%B3%CC%CD%A8%D6%AA.html

http://www.cocoachina.com/bbs/read.php?tid=102110


csdn上的资料:http://www.csdn.net/article/2012-02-18/311976

http://blog.csdn.net/cleverbobywjb/article/details/40109971


自己遇到的问题

1. error : Error Domain=NSCocoaErrorDomain Code=3000 "未找到应用程序的“aps-environment”的权利字符串" UserInfo=0x1187ad0 


程序回调委托

- (void)application:(UIApplication*)application  didFailToRegisterForRemoteNotificationsWithError:(NSError*)error

{

    NSLog(@"获得令牌失败: %@", error);

}

返回错误:error : Error Domain=NSCocoaErrorDomain Code=3000 "未找到应用程序的“aps-environment”的权利字符串" UserInfo=0x1187ad0 

我的出错的原因是Xcode的Bundle Identifier 与证书的app id不一致

要确保这三个地方一致

技术分享技术分享技术分享

如果第一个图中的Bundle Identifier不能修改,看第二个图中Bundle Identifier的值,可能是第二个图中的设置让第一个图不能修改的。

我是直接让这两个值都和第三个图中的值一样。


2.xcode使用不正确的配置文件Provisioning Profile

xcode自动使用带*的配置文件,这是不允许的。我是指定了要使用的配置文件:

技术分享

点击Debug 值的地方,会出现可选的Provisioning Profile:

技术分享

因为我是Debug版,所以设置Debug的 Provisioning Profile为制定的Provisioning Profile,不使用Automatic.

3.根据上面英文链接到在终端运行

php simplepush.php

出现

Warning: stream_socket_client(): Unable to set private key file `/Users/ensurebit/Desktop/SimplePush/ck.pem‘ in /Users/ensurebit/Desktop/SimplePush/simplepush.php on line 22

Warning: stream_socket_client(): failed to create an SSL handle in /Users/ensurebit/Desktop/SimplePush/simplepush.php on line 22

Warning: stream_socket_client(): Failed to enable crypto in /Users/ensurebit/Desktop/SimplePush/simplepush.php on line 22

Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in /Users/ensurebit/Desktop/SimplePush/simplepush.php on line 22

Failed to connect: 0 


检查了文件改修改的3个地方也修改了


<?php

// Put your device token here (without spaces):
$deviceToken = ‘不带空格的设备令牌‘;

// Put your private key‘s passphrase here:
$passphrase = ‘密码‘;

// Put your alert message here:
$message = ‘推送通知信息!‘;

////////////////////////////////////////////////////////////////////////////////

$ctx = stream_context_create();
stream_context_set_option($ctx, ‘ssl‘, ‘local_cert‘, ‘ck.pem自己的pem‘);

红色部分是需要修改成自己的值的。

上网各种差,真是抓耳挠腮。突然发现$passphrase = ‘密码‘;这行的密码两个字的单引号不对,是全角符号,然后改为半角符号,运行,成功!鼓掌!

$ php simplepush.php 

Connected to APNS

Message successfully delivered

这样表示成功。

一会自己的应用程序就收到了远程推送。




iOS 远程推送参考资料及自己遇到的问题

标签:

原文地址:http://blog.csdn.net/liyun123gx/article/details/42144509

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!