gpt4 book ai didi

ios - 本地通知不适用于 iOS 模拟器

转载 作者:行者123 更新时间:2023-11-28 11:09:34 25 4
gpt4 key购买 nike

我不确定我做错了什么。我有以下代码:

//Create date
let calendar = NSCalendar.currentCalendar()
let now = NSDate()

let dateComponents = calendar.components([NSCalendarUnit.Day, NSCalendarUnit.Month, NSCalendarUnit.Year, NSCalendarUnit.Hour, NSCalendarUnit.Minute, NSCalendarUnit.Second], fromDate: now)

dateComponents.minute += 2 //add 2 minutes to current time for debug

let date = calendar.dateFromComponents(dateComponents)

//Create notification
let notification = UILocalNotification()
notification.alertBody = "Your task is now available"
notification.alertAction = "open"
notification.fireDate = date
notification.soundName = UILocalNotificationDefaultSoundName
notification.userInfo = ["id": NSUUID().UUIDString]
notification.category = "Notification"
UIApplication.sharedApplication().scheduleLocalNotification(notification)

当我在应用程序中放置一个断点时:应用程序委托(delegate)中的 didReceiveLocalNotification,它永远不会被调用。

最佳答案

好的,我会回答我自己的问题。在 AppDelegate: didFinishLaunchingWithOptions 中,我必须像这样注册通知:

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

关于ios - 本地通知不适用于 iOS 模拟器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35997059/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com