2014-07-24 47 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它可能不響選擇,我已經加了聲音文件在我的應用程序包中,並用於在我的代碼中以聲音名稱的形式播放該文件,它每次都會工作