在应用商店中提交应用时,本地通知无效

时间:2017-02-08 15:28:39

标签: ios swift swift3 uilocalnotification localnotification

我有一个问题,当我提交应用更新时,本地通知无法正常工作。我已经在我的设备中进行了测试并且它正在运行,但是当我从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
            }

我希望有人可以帮助我,我已尝试过所有解决方案,但除了我的开发设备之外,仍然没有为用户工作

1 个答案:

答案 0 :(得分:0)

通知委托问题 并检查通知的时间和日期