简体   繁体   English

PN(推送通知)远程通知到达时如何长时间播放声音

[英]how can I play sound for long time when PN(push-notification) remote notification arrive

当使用Objective-c PN(推送通知)到达设备时,如何重复声音文件。

You can find how to Custom Alert Sounds in this website: Managing Your App's Notification Support and the ringtone can not be Over 30s 您可以在以下网站中找到如何自定义警报声音的方法: 管理应用程序的通知支持 ,并且铃声不能超过30秒

Preparing Custom Alert Sounds 准备自定义警报声音

For remote notifications in iOS, you can specify a custom sound that iOS plays when it presents a local or remote notification for an app. 对于iOS中的远程通知,您可以指定iOS呈现应用的本地或远程通知时播放的自定义声音。 The sound files must be in the main bundle of the client app. 声音文件必须位于客户端应用程序的主捆绑包中。

Custom alert sounds are played by the iOS system-sound facility, so they must be in one of the following audio data formats: 自定义警报声音是由iOS系统声音设备播放的,因此它们必须采用以下音频数据格式之一:

Linear PCM 线性PCM

MA4 (IMA/ADPCM) MA4(IMA / ADPCM)

µLaw 微法

aLaw 一条法律

You can package the audio data in an aiff, wav, or caf file. 您可以将音频数据打包为aiff,wav或caf文件。 Then, in Xcode, add the sound file to your project as a nonlocalized resource of the app bundle. 然后,在Xcode中,将声音文件作为应用程序包的非本地化资源添加到您的项目中。

You may use the afconvert tool to convert sounds. 您可以使用afconvert工具转换声音。 For example, to convert the 16-bit linear PCM system sound Submarine.aiff to IMA4 audio in a CAF file, use the following command in the Terminal app: 例如,要将16位线性PCM系统声音Submarine.aiff转换为CAF文件中的IMA4音频,请在终端应用程序中使用以下命令:

afconvert /System/Library/Sounds/Submarine.aiff ~/Desktop/sub.caf -d ima4 -f caff -v

You can inspect a sound to determine its data format by opening it in QuickTime Player and choosing Show Movie Inspector from the Movie menu. 通过在QuickTime Player中打开声音并从“电影”菜单中选择“显示电影检查器”,可以检查声音以确定其数据格式。

Custom sounds must be under 30 seconds when played. 自定义声音播放时必须在30秒以内。 If a custom sound is over that limit, the default system sound is played instead. 如果自定义声音超过该限制,则会播放默认的系统声音。

You can make this example dictionary send to APNs server with your custom alert sound name for the value of 'sound' : 您可以使用自定义警报声音名称将此示例字典发送到APNs服务器,以获取'sound'的值:

// Create the payload body
$body['aps'] = array(
                    'alert' => 'TestNotification',
                    'sound' => 'YourCustomAlertSoundName.caf',
                    'badge' => 8

After making a good ringtone to your project's main bundle, the important step is to add the sound file you added (YourCustomAlertSoundName.caf) to Build Phases-> Copy Bundle Resources in the Project Settings, and the ringtone can not be Over 30s, otherwise the system will enable the default ringtone (default). 在为项目的主捆绑包制作好铃声后,重要的步骤是将添加的声音文件(YourCustomAlertSoundName.caf)添加到项目设置中的“构建阶段”->“复制捆绑包资源”中,并且铃声不能超过30秒,否则系统将启用默认铃声(默认)。

You just have to set custom file into sound on push payload. 您只需要在推送有效载荷上将自定义文件设置为声音即可 Put the same audio file into your build resource and just fire notification from server, it will play audio. 将相同的音频文件放入您的构建资源中,然后从服务器启动通知,它将播放音频。

{
   "aps" : 
   { 
       "alert" : "This is your alert text" 
       "sound" : "YOUR_COSTOM_FILE_NAME.mp4"
   },
}

When the application is in foreground mode, then you need to play same audio file when you get receive notification. 当应用程序处于前台模式时,则在收到接收通知时需要播放相同的音频文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM