gpt4 book ai didi

ios - Apple Push Notification 不适用于临时构建而不是开发

转载 作者:行者123 更新时间:2023-11-29 03:18:16 25 4
gpt4 key购买 nike

在开发模式下,我可以向设备发送推送通知,但在生产模式下我不能,我的设置是:

--> 我已经从配置门户下载了 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' with 2195 port

-->问题是我的 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

消息发送成功

最佳答案

注意设备 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];
}

关于ios - Apple Push Notification 不适用于临时构建而不是开发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21423625/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com