繁体   English   中英

如何在iphone中的UILocalNotification中更改自定义声音?

[英]How to change custom sound in UILocalNotification in iphone?

我在ios的uilocalnotification中使用自定义声音。 但它没有发挥。 文件存在于Document文件夹中。 通知正在使用local.soundName= UILocalNotificationDefaultSoundName;

        NSString* documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
        NSString *path = [NSString stringWithFormat:@"%@/DingDongTone.wav",documentsPath];
        local.soundName=path;

请帮忙。 谢谢。

请重新阅读苹果所说的内容 -

对于此属性,请指定应用程序主bundle或UILocalNotificationDefaultSoundName声音资源的文件名(包括扩展名)以请求默认系统声音。 当系统显示本地通知的警报或标记应用程序图标时,它会播放此声音。 默认值为nil (无声音)。 不支持持续时间超过30秒的声音。 如果您指定的声音播放时间超过30秒,则会播放默认声音。

根据此filename是不在document directorymain bundle资源中的文件path

注意:文件也不应超过30 sec.

@saadnib说我完全同意他sound resource should in the application's main bundle specify the filename sound resource should in the application's main bundle specify the filename (包括扩展名)

所以在应用程序的主程序包中复制你的声音,然后不要forget to copy你的path string ,它应该工作。

  yourLocalNotification.soundName= [yourSoundFilePath copy];

暂无
暂无

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

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