Apple 推送通知不适用于非开发中的临时构建 [英] Apple Push Notification not working with ad-hoc build not on development
问题描述
在开发模式下,我可以向设备发送推送通知,而不是在生产模式下,我的设置是:
In development mode I can send push notification to devices, instead I can't in production, my setup is:
--> 我已经从配置门户下载了 aps_production.cer 证书,然后双击 aps_production.cer 安装的钥匙串访问,最后从钥匙串访问中获取私钥,当时它要求输入密码我已经给出了一些密码,如admin".
--> 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
--> openssl pkcs12 -in CertificateName_pro.p12 -out CertificateName_pro.pem -nodes
--> 苹果服务器 apn: 'gateway.push.apple.com' 2195 端口
--> apple server apn: 'gateway.push.apple.com' with 2195 port
-->问题是我的 rails 应用程序发送了通知并且没有收到任何错误,但是设备上没有任何内容.
-->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
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);
在终端上运行时
Mac:test macmini$ php simplepush.php
Mac:test macmini$ php simplepush.php
连接到 APNS
消息发送成功
推荐答案
请注意设备令牌 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];
}
这篇关于Apple 推送通知不适用于非开发中的临时构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!