在应用商店提交应用时本地通知不起作用
Local Notification not working when submit app in app store
我遇到了一个问题,当我为我的应用程序提交更新时本地通知不起作用。我已经在我的设备上进行了测试,它可以正常工作,但是当我从 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 ✌"
content.sound = UNNotificationSound.default()
let date = dateFormatter.date(from: currentGame.gameDate)
let triggerDate = Calendar.current.dateComponents([.year,.month,.day,.hour,.minute,.second], from: date!)
let trigger = UNCalendarNotificationTrigger(dateMatching: triggerDate, repeats: false)
let indetifier = "UYLLocalNotification"
let request = UNNotificationRequest(identifier: indetifier, content: content, trigger: trigger)
center.add(request, withCompletionHandler: { (error) in
if error != nil{
print("Something went wrong here ")
}
})
}
else {
gamesCountdownLabel.text! = countdownText
}
我希望有人能帮我解决我已经尝试了所有的解决方案,但除了我的开发设备之外,仍然无法为用户工作
通知委托有问题
并检查通知的时间和日期
我遇到了一个问题,当我为我的应用程序提交更新时本地通知不起作用。我已经在我的设备上进行了测试,它可以正常工作,但是当我从 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 ✌"
content.sound = UNNotificationSound.default()
let date = dateFormatter.date(from: currentGame.gameDate)
let triggerDate = Calendar.current.dateComponents([.year,.month,.day,.hour,.minute,.second], from: date!)
let trigger = UNCalendarNotificationTrigger(dateMatching: triggerDate, repeats: false)
let indetifier = "UYLLocalNotification"
let request = UNNotificationRequest(identifier: indetifier, content: content, trigger: trigger)
center.add(request, withCompletionHandler: { (error) in
if error != nil{
print("Something went wrong here ")
}
})
}
else {
gamesCountdownLabel.text! = countdownText
}
我希望有人能帮我解决我已经尝试了所有的解决方案,但除了我的开发设备之外,仍然无法为用户工作
通知委托有问题 并检查通知的时间和日期