不工作的本地通知声音 [英] Local notification sound not working
本文介绍了不工作的本地通知声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图做出正确的报警程序,但是当我尝试做一个本地通知我无法播放声音。我得到这个错误:
[用户信息=(空)}具有健全的,但还没有收到许可用户播放声音]
下面是code:
@IBOutlet VAR setAlaram:的UIDatePicker!
@IBAction FUNC setAlarmButton(发件人: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) [自.localnotification(setAlaram.date)}FUNC localnotification(firedate:NSDate的){ VAR localNotification:UILocalNotification = UILocalNotification()
localNotification.fireDate = firedate
localNotification.alertBody =时间醒过来
localNotification.soundName =alarm.wav
UIApplication.sharedApplication()。scheduleLocalNotification(localNotification)}覆盖FUNC viewDidLoad中(){
super.viewDidLoad()
让DATE1 = NSDate的()
setAlaram.date = DATE1}
解决方案
您需要征得他的许可用户在iOS 8的发送本地通知。
您可以这样做,当你的AppDelegate方法,你的应用程序启动
FUNC应用程序(应用程序:UIApplication的,didFinishLaunchingWithOptions launchOptions:[NSObject的:AnyObject]) - GT;布尔{
application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes:.Sound | .Alert | .Badge,类别:无))
返回true
}
I'm trying to make an alarm app but when I try to make a local notification I am unable to play the sound. I got this error:
[user info = (null)} with a sound but haven't received permission from the user to play sounds]
Here is the code:
@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
}
解决方案
You need to ask the user for permission to send local notifications in iOS 8.
You can do so when you application launches in your AppDelegate methods
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: .Sound | .Alert | .Badge, categories: nil))
return true
}
这篇关于不工作的本地通知声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文