简体   繁体   English

iOS Swift本地通知没有声音

[英]ios swift local notifications no sound

Iam trying to make a regular UILocalNotification with default sound 我试图用默认声音制作常规的UILocalNotification

this is my function 这是我的职责

func makeLocalNotificationForNow(str : String , id : String)
{
let notification = UILocalNotification()


notification.alertBody = str // text that will be displayed in the notification
notification.alertAction = "open" // text that is displayed after "slide to..." on the lock screen - defaults to "slide to view"
notification.fireDate = NSDate(timeIntervalSinceNow: 5) // todo item due date (when notification will be fired)
notification.soundName = UILocalNotificationDefaultSoundName // play default sound
UIApplication.sharedApplication().scheduleLocalNotification(notification)
}

in my didFinishLaunchingWithOptions function I put 在我的didFinishLaunchingWithOptions函数中

let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge , .Sound], categories: nil)
            application.registerUserNotificationSettings(settings)
            application.registerForRemoteNotifications()

Note : I also use parse push notifications 注意:我也使用解析推送通知

when I make the notification , it appears but without an alert or sound (I need to swipe the from top to see the notification what's wrong ?! 当我发出通知时,它会出现,但没有警报或声音(我需要从顶部滑动以查看通知,这是怎么回事?!

据我所知,只有当应用程序在后台运行时,通知才会发出声音,这意味着退出应用程序,将手机置于锁定模式,并通过解析网站发送通知,那么您应该听到声音,如果没有,请检查在您正在执行的应用程序上进行设置,以查看是否启用了声音警报以及最新资源,请检查您的手机不是仅振动

这是一个愚蠢的错误,问题出在我的手机上,我换了手机,一切正常

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM