Custom Sound APNS

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

my sound is called wil.caf and I have it in my xcode project.

this is my php sript to trigger a push message:

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

+3
source share
1 answer

Your test payload indicates "default" as the sound to play. If you want to play custom sound, make sure that the sound file is in the application bundle and specify it as follows (using the Apple bingpong.aiff sample sound file):

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

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

+6

All Articles