2014-07-24 49 views
1

基于此教程Simple iOS Alarm Clock Tutorial我实现了AlarmClock应用程序。 通知功能正常,但没有声音。LocalNotification - ios 7.1模拟器上的UILocalNotificationDefaultSoundName不起作用

为了解决这个问题,我尝试过: Fix-1并取消选中/检查了我的MacOS声音设置。

我能做些什么来获得简单的AlarmClock声音? (信息:YouTube的声音作品@模拟器)

代码:

-(void)scheduleLocalNotificationWithDate:(NSDate *)fireDate 
{ 

    [[UIApplication sharedApplication] cancelAllLocalNotifications]; 

    UILocalNotification *notification = [UILocalNotification new]; 
    notification.fireDate = fireDate; 
    notification.soundName = UILocalNotificationDefaultSoundName; 
    notification.alertBody = @"Wake-up... !!!"; 
    notification.alertAction = @"OK"; 

    //[notification setApplicationIconBadgeNumber:-1]; 
    notification.applicationIconBadgeNumber = 1; // increment 

    [[UIApplication sharedApplication] scheduleLocalNotification:notification]; 
} 

回答

2

您的代码是正确的。这只是因为模拟器的声音不能很好地工作。例如,也没有键盘声音。如果您将自定义声音分配给您的本地通知,它就会起作用。

+0

你是对的!干杯 – blub

1

如果你的默认声音名称在您Simulator不是那么当你正在使用UILocalNotificationDefaultSoundName它可能不响选择,我已经加了声音文件在我的应用程序包中,并用于在我的代码中以声音名称的形式播放该文件,它每次都会工作