当我为我的应用程序提交更新时,本地通知不起作用。我已经在我的设备上进行了测试,它可以正常工作,但是当我从 AppStore 下载应用程序时,通知根本不起作用 这里的代码是 AppDelgate :
class AppDelegate: UIResponder, UIApplicationDelegate,UNUserNotificationCenterDelegate
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
}
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler([.alert,.sound])
}
并且我已经实现了这段代码,以便在计时器击中发布日期时发送通知
import UserNotifications
let center = UNUserNotificationCenter.current()
let options : UNAuthorizationOptions = [.alert, .sound, .badge]
center.requestAuthorization(options: options) { (granted, error) in
if !granted {
print("Somthing went wrong")
}
}
center.getNotificationSettings { (settings) in
if settings.authorizationStatus != .authorized {
print("Notification not allowd")
}
}
here is in different function that calculate the time and send notification, I have not put the code for timer to make it more visual for others
let content = UNMutableNotificationContent()
content.title = NSLocalizedString("NOTIFICATION_TITLE", comment: "Game Released")
content.body = "\(self.currentGame.gameName) Released ✌
欢迎光临 OGeek|极客世界-中国程序员成长平台 (https://ogeek.cn/)
Powered by Discuz! X3.4