我正在使用以下代码在收到远程通知时安排本地通知,
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/