问题描述
我在我的应用程序中实现了本地通知,但我只是想知道是否有一种方法可以播放不属于主要iPhone应用程序包的声音。
基本上在我的应用中,我希望用户录制在生成本地通知时播放的声音,而不是播放预先录制的或默认声音。
据我所知,这可以实现,因为我在应用程序商店看到2-3个应用程序正在做我想做的事情
I implemented local notification in my app but I am just wondering is there a way to play a sound that is not part of the main bundle of iPhone App.Basically in my app, I want user to record a sound that gets played when the local notification is generated instead of playing a pre-recorded or default sound.As far as i know this can be implementable because i have seen 2-3 App in app store which is doing the same thing which i want to do
- (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];
}
推荐答案
我的猜测是你的声音不是格式化适合操作系统播放。确保您的声音格式为IMA4格式。此外,请确保您的文件在您的应用程序包中,并且您应该好好去。
My guess is your sound isn't formatted appropriately to play by the OS. Make sure your sound is formatted in IMA4 format. Also, make sure your file is in your application bundle, and you should be good to go.
有关更多参考和类似问题,请参阅此SO问题。
For more reference and similar question, see this SO question.
这是。它详细解释了声音和可以使用的默认声音。
Here is a link for Apple's Local and Push Notification Guide. It explains the sounds in detail and the default sounds that can be used.
这篇关于UILocalNotifications播放自定义声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!