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

来源:互联网 发布:王勇java 编辑:程序博客网 时间:2024/05/16 14:01

很好的参考资料: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

 

比较详细介绍各种证书配置文件的:http://blog.sina.com.cn/s/blog_7bfb9660010144j6.html

 

bound name 和 APP ID  的关系http://blog.csdn.net/totogogo/article/details/7377870

 

可能出现的问题及各种点击调用app的情况:http://blog.csdn.net/totogogo/article/details/7385487


另外还有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

这样表示成功。

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




0 0
原创粉丝点击