苹果推送通知与临时搭建不开发工作 [英] Apple Push Notification not working with ad-hoc build not on development
问题描述
在开发模式下,我可以发送推送通知的设备,而不是我不能在生产中,我的设置是:
- >我从供应门户下载aps_production.cer证书,然后双击安装aps_production.cer钥匙串访问终于得到当时它要求密码钥匙串访问私钥我已经给像admin的一些密码
- > OpenSSL的PKCS12 -in CertificateName_pro.p12退房手续CertificateName_pro.pem -nodes
- >苹果服务器APN:gateway.push.apple.com与2195端口
- >的问题是,我的Rails应用程序发送通知并没有收到任何错误,但没有到达设备
。 - (无效)应用:(*的UIApplication)应用didRegisterForRemoteNotificationsWithDeviceToken:(NSData的*)deviceToken {
的NSString * deviceTokenStr = [[[[deviceToken描述]
stringByReplacingOccurrencesOfString:@< withString:@]
stringByReplacingOccurrencesOfString:@>中withString:@]
stringByReplacingOccurrencesOfString:@withString:@]; }
simplepush.php
< PHP//把你的设备令牌这里(无空格):
$ deviceToken ='deviceTokenStr';//把你的私钥的密码在这里:
$密码='管理员';//这里把你的警告信息:
$消息='你有管理的一个新问题!;////////////////////////////////////////////////// //////////////////////////////$ CTX = stream_context_create();
stream_context_set_option($ CTXSSL,的local_cert','CertificateName_pro.pem');
stream_context_set_option($ CTX,'SSL','管理',$密码);//打开到APNS服务器的连接
$计划生育=在stream_socket_client(
SSL://gateway.push.apple.com:2195',$犯错,
$ errstr,60,STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT,$ CTX);如果(!$ FP)
退出(无法连接:$犯错$ errstrPHP_EOL);回声连接到APNS。 PHP_EOL;//创建有效载荷体
$身体['APS'] =阵列(
'警报'=> $消息,
声音= GT; '默认',
'徽章'
);// EN code中的有效载荷为JSON
$有效载荷= json_en code($体);//生成二进制通知
$味精= CHR(0)。包('N',32)。包(H *',$ deviceToken)。包('N',strlen的($有效载荷))。 $有效载荷;//它发送到服务器
$结果=的fwrite($计划生育,$味精,strlen的($味精));如果(!$结果)
回声消息发送失败。 PHP_EOL;
其他
回声的消息成功传递。 PHP_EOL;//关闭与服务器的连接
FCLOSE($ FP);
在终端上运行
苹果:测试macmini $ PHP simplepush.php
连接到APNS
信息成功发送
请为了解设备令牌ID的
,
这是发展和放大器不同;&安培;生产环境。
块引用>- (无效)应用:(*的UIApplication)应用didRegisterForRemoteNotificationsWithDeviceToken:(NSData的*)deviceToken {
的NSString * deviceTokenStr = [[[[deviceToken描述]
stringByReplacingOccurrencesOfString:@< withString:@]
stringByReplacingOccurrencesOfString:@>中withString:@]
stringByReplacingOccurrencesOfString:@withString:@];
UIAlertView中*警报= [[UIAlertView中页头] initWithTitle:deviceTokenStr消息:无委托:自我cancelButtonTitle:@OKotherButtonTitles:无];
[警报显示]
}In development mode I can send push notification to devices, instead I can't in production, my setup is:
--> I have downloaded aps_production.cer certificates from provisioning portal and then double click the aps_production.cer installed keychain access finally get the private key from keychain access at that time it asked password i have given some password like "admin".
--> openssl pkcs12 -in CertificateName_pro.p12 -out CertificateName_pro.pem -nodes
--> apple server apn: 'gateway.push.apple.com' with 2195 port
-->The problem is that my rails application sends notifications and didn't receive any errors, but nothing arrived on devices.
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { NSString *deviceTokenStr = [[[[deviceToken description] stringByReplacingOccurrencesOfString: @"<" withString: @""] stringByReplacingOccurrencesOfString: @">" withString: @""] stringByReplacingOccurrencesOfString: @" " withString: @""]; }
simplepush.php
<?php // Put your device token here (without spaces): $deviceToken = 'deviceTokenStr'; // Put your private key's passphrase here: $passphrase = 'admin'; // Put your alert message here: $message = 'You have a new issue of admin!'; //////////////////////////////////////////////////////////////////////////////// $ctx = stream_context_create(); stream_context_set_option($ctx, 'ssl', 'local_cert', 'CertificateName_pro.pem'); stream_context_set_option($ctx, 'ssl', 'admin', $passphrase); // Open a connection to the APNS server $fp = stream_socket_client( 'ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx); if (!$fp) exit("Failed to connect: $err $errstr" . PHP_EOL); echo 'Connected to APNS' . PHP_EOL; // Create the payload body $body['aps'] = array( 'alert' => $message, 'sound' => 'default', 'badge' ); // Encode the payload as JSON $payload = json_encode($body); // Build the binary notification $msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload; // Send it to the server $result = fwrite($fp, $msg, strlen($msg)); if (!$result) echo 'Message not delivered' . PHP_EOL; else echo 'Message successfully delivered' . PHP_EOL; // Close the connection to the server fclose($fp);
While run on terminal
Mac:test macmini$ php simplepush.php
Connected to APNS
Message successfully delivered
解决方案Please be
aware of the device token-ID
,which is different for the development && Production environment .
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { NSString *deviceTokenStr = [[[[deviceToken description] stringByReplacingOccurrencesOfString: @"<" withString: @""] stringByReplacingOccurrencesOfString: @">" withString: @""] stringByReplacingOccurrencesOfString: @" " withString: @""]; UIAlertView *alert= [[UIAlertView alloc]initWithTitle:deviceTokenStr message:Nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil]; [alert show]; }
这篇关于苹果推送通知与临时搭建不开发工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!