У меня проблема, когда локальное уведомление не работает, когда я отправляю обновление для своего приложения. Я протестировал свое устройство, и оно работало, но когда я загружаю приложение из 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
}
Я надеюсь, что кто-то может мне помочь. Я пробовал все решения, но все еще не работал для пользователей, кроме моего устройства разработки.