我試圖製作鬧鐘應用程序,但是當我嘗試進行本地通知時,我無法播放聲音。我得到這個錯誤:本地通知聲音無法正常工作
[user info = (null)} with a sound but haven't received permission from the user to play sounds]
下面是代碼:
@IBOutlet var setAlaram: UIDatePicker!
@IBAction func setAlarmButton(sender: AnyObject) {
var dateformater = NSDateFormatter()
dateformater.timeZone = NSTimeZone .defaultTimeZone()
dateformater.timeStyle = NSDateFormatterStyle.ShortStyle
dateformater.dateStyle = NSDateFormatterStyle.ShortStyle
var datetimestring = NSString()
datetimestring = dateformater.stringFromDate(setAlaram.date)
println(datetimestring)
[self .localnotification(setAlaram.date)]
}
func localnotification (firedate:NSDate) {
var localNotification:UILocalNotification = UILocalNotification()
localNotification.fireDate = firedate
localNotification.alertBody = "time to woke up"
localNotification.soundName = "alarm.wav"
UIApplication.sharedApplication().scheduleLocalNotification(localNotification)
}
override func viewDidLoad() {
super.viewDidLoad()
let date1 = NSDate()
setAlaram.date = date1
}
的'localnotification'爲*功能的使用*名稱是有點混亂... – Honey 2017-02-13 16:56:29