不工作的本地通知声音

编程入门 行业动态 更新时间:2024-10-26 08:30:31
本文介绍了不工作的本地通知声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图做出正确的报警程序,但是当我尝试做一个本地通知我无法播放声音。我得到这个错误:

[用户信息=(空)}具有健全的,但还没有收到许可用户播放声音]

下面是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 }

更多推荐

不工作的本地通知声音

本文发布于:2023-11-27 01:57:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636095.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:声音   通知   工作

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!