苹果推送通知不适用于专门构build而不是开发

在开发模式下,我可以发送推送通知到设备,而不是在生产中,我的设置是:

– >我已经从configuration门户网站下载了aps_production.cer证书,然后双击aps_production.cer安装的钥匙串访问权限,最后从密钥链访问中获得私钥,当时它询问密码我给了一些像“admin”这样的密码。

– > openssl pkcs12 -in CertificateName_pro.p12 -out CertificateName_pro.pem -nodes

– >苹果服务器apn:“gateway.push.apple.com”与2195端口

– >问题是我的rails应用程序发送通知,并没有收到任何错误,但没有到达设备上。

- (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); 

在terminal上运行

Mac:testingmacmini $ php simplepush.php

连接到APNS

消息已成功发送

aware of the device token-ID

这对于开发&生产环境是不同的。

  - (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]; } 
Interesting Posts