首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UILocalNotifications播放自定义声音

UILocalNotifications播放自定义声音
EN

Stack Overflow用户
提问于 2011-08-18 12:53:18
回答 6查看 8K关注 0票数 9

我在我的应用程序中实现了本地通知,但我只是想知道是否有一种方法可以播放不属于iPhone应用程序主包的声音。基本上,在我的应用程序中,我希望用户录制在本地通知生成时播放的声音,而不是播放预先录制或默认的声音。据我所知,这是可以实现的,因为我在应用程序商店中看到了2-3个应用程序,它们做的是我想做的事情

代码语言:javascript
复制
- (void)alertSelector:(NSString *)AlertTitle WithFiringTime:(NSDate *)date
{ 

UILocalNotification *localNotification = [[[UILocalNotification alloc] init] autorelease];
   [localNotification setFireDate:date];
   [localNotification setTimeZone:[NSTimeZone defaultTimeZone]];
   NSDictionary *data = [NSDictionary dictionaryWithObject:date forKey:@"payload"];       
   [localNotification setUserInfo:data];[localNotification setAlertBody:AlertTitle];   
   [localNotification setAlertAction:@"View"]; [localNotification setHasAction:YES]; 
   localNotification.soundName=@"voice.aif"; 

   if (!localNotification)
          return;

    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; 
}
EN

回答 6

Stack Overflow用户

发布于 2012-02-04 03:25:55

我猜你的声音格式不适合操作系统播放。确保您的声音格式为IMA4格式。此外,请确保您的文件在应用程序包中,这样就可以运行了。

有关更多参考和类似问题,请参阅此SO问题。

Choose custom sound for Local Notifications

这里有一个Apple's Local and Push Notification Guide的链接。它详细解释了声音和可以使用的默认声音。

票数 3
EN

Stack Overflow用户

发布于 2011-08-18 13:24:50

soundName属性的描述可以看出-

对于此属性,请在应用程序的主包或UILocalNotificationDefaultSoundName中指定声音资源的文件名(包括扩展名)以请求默认系统声音。

除了捆绑包中存在的声音之外,似乎没有其他声音可以使用。您确定应用程序正在使用带有自定义声音的本地通知吗?也许他们正在播放带有警报的声音或类似的东西。

HTH,

阿克沙伊

票数 0
EN

Stack Overflow用户

发布于 2015-08-21 14:19:03

代码语言:javascript
复制
notif.soundName = @"sound.caf";

应该可以工作的

。确保声音确实在你的应用程序包中,是正确的格式(线性PCM或IMA4-几乎任何解释如何将声音转换为iOS的地方都会告诉你如何转换),并且不超过30秒。

可以使用terminal从wav和mp3进行转换:

代码语言:javascript
复制
afconvert -f caff -d LEI16@44100 -c 1 in.wav sound.caf

'in.wav‘是你想要转换的输入声音,'sound.caf’是输出文件,切换到你想要输出文件的目录

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7102552

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档