2015-10-13 44 views
1

每當我創建一個UILocalNotification並且它被觸發時,我只能每隔一秒播放一次自定義聲音。這隻發生在模擬器之外,在我的iPhone 5s上。UILocalNotification聲音每隔一段時間播放

UILocalNotification* sessionEndNotification = [UILocalNotification new]; 
sessionEndNotification.fireDate = [self.dateAppMinimized dateByAddingTimeInterval:[self secondsLeft]]; 
sessionEndNotification.alertBody = @"Your session has finished. Remember to remain mindful through the rest of your day!"; 
sessionEndNotification.soundName = @"bell.caf"; 
[[UIApplication sharedApplication] scheduleLocalNotification:sessionEndNotification]; 

如果我將soundName更改爲UILocalNotificationDefaultSoundName,它每次都有效。 bell.caf長8秒。

我在做什麼錯?

謝謝!

+0

您能指定更多詳細信息嗎?這並不清楚。 – KChen

+1

基本上,每次部署通知時(電話被鎖定時)聲音都不播放,並且不會振動。所以它工作一半時間。如果我使用默認聲音名稱,則每次都有效。 – MaitlandMarshall

回答

0

我修正了它,但沒有做任何有意義的事情。我將代碼更改爲此並且它可以工作:

UILocalNotification* sessionEndNotification = [UILocalNotification new]; 
sessionEndNotification.soundName = @"endMeditationBell.aif"; 
sessionEndNotification.hasAction = YES; 
sessionEndNotification.fireDate = [self.dateAppMinimized dateByAddingTimeInterval:[self secondsLeft]]; 
sessionEndNotification.alertTitle = @"Session finished"; 
sessionEndNotification.alertBody = @"Your session has finished. Remember to remain mindful through the rest of your day!"; 
[[UIApplication sharedApplication] scheduleLocalNotification:sessionEndNotification]; 
+0

沒有爲我工作,我有「每隔一段時間自定義聲音熄滅」的問題。我會繼續嘗試不同的東西! –