xcode APNS 自定义声音

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10324971/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 00:06:00  来源:igfitidea点击:

APNS Custom Sound

phpxcodeaudioapple-push-notifications

提问by user1110365

i want to send a push notification with a custom sound, but always i try, i only hear the default thing.

我想发送带有自定义声音的推送通知,但我总是尝试,我只听到默认的声音。

my sound is named wil.caf and i have it in my xcode project.

我的声音被命名为 wil.caf,我的 xcode 项目中有它。

this is my php sript to fire the push message:

这是我的 php sript 来触发推送消息:

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

}

?>

can anybody help me?

有谁能够帮助我?

回答by Jason

Your sample payload is specifying 'default' as the sound to play. If you want to play a custom sound, make sure the sound file is in the application bundle and specify it as follows (using Apple's example bingpong.aiff sound file):

您的示例负载将“默认”指定为要播放的声音。如果要播放自定义声音,请确保声音文件在应用程序包中并按如下方式指定(使用 Apple 的示例 bingpong.aiff 声音文件):

$payload['aps'] = array('alert' => $message, 'badge' => 0, 'sound' => 'bingbong.aiff'

Full APNS documentation: http://developer.apple.com/library/ios/#DOCUMENTATION/NetworkingInternet/Conceptual/RemoteNotificationsPG/ApplePushService/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW9

完整的 APNS 文档:http: //developer.apple.com/library/ios/#DOCUMENTATION/NetworkingInternet/Conceptual/RemoteNotificationsPG/ApplePushService/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW9