gpt4 book ai didi

ios - 没有互联网 iOS swift 无法接收本地通知

转载 作者:行者123 更新时间:2023-11-28 08:38:48 24 4
gpt4 key购买 nike

我正在使用以下代码在收到远程通知时安排本地通知,

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {

let scheduleLocalNotification = UILocalNotification()
scheduleLocalNotification.fireDate = dateFromRemoteNotification
scheduleLocalNotification.timeZone = NSTimeZone.localTimeZone()
scheduleLocalNotification.alertBody = "Hi There!"
scheduleLocalNotification.userInfo = userInfo
UIApplication.sharedApplication().scheduleLocalNotification(scheduleLocalNotification)
completionHandler(.NewData)
}

成功安排本地通知后。现在,我关闭了互联网,我没有收到本地通知..

有人遇到同样的问题吗?还是我错过了什么?

最佳答案

对于本地通知,在您的 appDelegate 的 didFinishLaunchingWithOptions 中编写此代码:-

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

//并在 Controller 中安排通知:-

let notification:UILocalNotification = UILocalNotification()
notification.alertTitle = " "
notification.alertBody = ""
notification.fireDate = NSDate()
UIApplication.sharedApplication().scheduleLocalNotification(notification)

关于ios - 没有互联网 iOS swift 无法接收本地通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36906308/

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