ios swift本地通知没有声音

时间:2015-10-22 17:35:46

标签: ios arrays uilocalnotification

Iam尝试使用默认声音进行常规UILocalNotification

这是我的功能

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)
}

在我的didFinishLaunchingWithOptions函数中,我把

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

注意:我还使用解析推送通知

当我发出通知时,它会显示但没有警报或声音(我需要从顶部滑动以查看通知 什么错了?!

2 个答案:

答案 0 :(得分:0)

据我所知,通知仅在应用程序处于后台时发出声音,意味着退出应用程序,将手机置于锁定模式并通过解析网站发送通知,然后您应该听到声音,如果不是,检查您正在制作的应用程序上的设置,以查看是否启用了声音警报,以及上次资源,检查您的手机是否仅处于振动状态

答案 1 :(得分:0)

这是一个愚蠢的错误,问题是我的手机,我换了手机,这一切都有效。