Apple推送通知不适用于ad-hoc构建而不是开发

时间:2014-01-29 06:24:27

标签: ios apple-push-notifications ad-hoc-distribution

在开发模式下,我可以向设备发送推送通知,而我无法投入生产,我的设置是:

- >我从配置门户下载了aps_production.cer证书,然后双击aps_production.cer安装的keychain访问,最后从keychain访问获取私钥,当时它询问密码我已经给了一些密码,如“admin”。

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

- > apple server 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);

在终端上运行

Mac:测试macmini $ php simplepush.php

连接到APNS

消息已成功发送

1 个答案:

答案 0 :(得分:1)

aware of the device token-ID

  

这对于开发和&amp;&amp;生产环境。

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