Php APNS自定义声音
我想发送带有自定义声音的推送通知,但我总是尝试,我只听到默认的声音 我的声音名为wil.caf,我的xcode项目中有它 这是触发推送消息的php sript:Php APNS自定义声音,php,xcode,audio,apple-push-notifications,Php,Xcode,Audio,Apple Push Notifications,我想发送带有自定义声音的推送通知,但我总是尝试,我只听到默认的声音 我的声音名为wil.caf,我的xcode项目中有它 这是触发推送消息的php sript: <?php $message = $_GET["message"]; $deviceToken = $_GET["token"]; $devideToken = dechex ($deviceToken); // Payload erstellen und JSON codieren $payload['aps'] =
<?php
$message = $_GET["message"];
$deviceToken = $_GET["token"];
$devideToken = dechex ($deviceToken);
// Payload erstellen und JSON codieren
$payload['aps'] = array('alert' => $message, 'badge' => 0, 'sound' => 'default');
$payload = json_encode($payload);
$apnsHost = 'gateway.push.apple.com';
$apnsPort = 2195;
$apnsCert = 'apsDevBundle2.pem';
// Stream erstellen
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);
if ($apns)
{
// Nachricht erstellen und senden
$apnsMessage = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $deviceToken)) . chr(0) . chr(strlen($payload)).$payload;
fwrite($apns, $apnsMessage);
// Verbindung schliessen
fclose($apns);
}
else
{
echo "Fehler!";
var_dump($error);
var_dump($errorString);
}
?>
有人能帮我吗?您的示例负载将“默认”指定为要播放的声音。如果要播放自定义声音,请确保该声音文件位于应用程序包中,并按如下方式指定(使用Apple的示例bingpong.aiff声音文件): 完整的APNS文档:
$payload['aps'] = array('alert' => $message, 'badge' => 0, 'sound' => 'bingbong.aiff'