Search code examples
iosswiftswift3uilocalnotificationlocalnotification

Local Notification not working when submit app in app store


I have an issue that Local Notification not working when I submitted an update for my app. I have tested out in my device and it was working but when I download app from AppStore the notification not working at all here is the code is 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])
    }

and I have implemented this code to send notification when the timer hit hit the day of the release

  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
            }

I hope someone can help me out I have tried all the solutions but still didn't working for users except my development device


Solution

  • Issue with notification delegate and check the time and date for notification