本地通知声音无效

时间:2012-08-29 06:40:14

标签: iphone objective-c ios xcode cocoa-touch

在iPhone应用中,

我正在设置本地通知。

我正在设置自定义声音。

通知到来时,我听不到任何声音。 甚至不是默认声音。

我的iPod touch和设备都没有。

任何机构都可以帮我找出原因吗?

非常感谢。

这是代码。

UILocalNotification *localNotification = [[UILocalNotification alloc] init];

localNotification.fireDate=[dateFormat dateFromString:alarm_date];

localNotification.alertBody = @"Alarm.";

localNotification.soundName = [filePath lastPathComponent];

//localNotification.soundName =soundname; 
//UILocalNotificationDefaultSoundName;

localNotification.applicationIconBadgeNumber = 1;

localNotification.alertAction=@"Show";


[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

[localNotification release];

答案 得到了傻瓜点:通知声音只在你的应用程序在后台或关闭时播放。 对不起这个问题。 无论如何,谢谢。

2 个答案:

答案 0 :(得分:2)

我认为这对你来说很有用.......

    UILocalNotification *localNotification = [[UILocalNotification alloc] init];

    localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:5];

    localNotification.timeZone = [NSTimeZone defaultTimeZone];
    localNotification.alertBody = @"You have long time to care your......";
    localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber]+1;
    localNotification.soundName = UILocalNotificationDefaultSoundName;
    localNotification.repeatInterval = kCFCalendarUnitMinute;
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
    [localNotification release];
    localNotification = nil;

答案 1 :(得分:2)

声音应少于30秒才能作为通知声音播放

其他事情:

根据Apple开发者文档,您需要使用“aiff”,“caf”或“wav”文件。