【问题标题】:Local Notification not working when submit app in app store在应用商店中提交应用时本地通知不起作用
【发布时间】:2017-02-08 15:28:39
【问题描述】:

当我为我的应用程序提交更新时,本地通知不起作用。我已经在我的设备上进行了测试,它可以正常工作,但是当我从 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
            }

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

【问题讨论】:

  • 请让我们知道究竟发生了什么“根本不工作”以及工作和非工作设备正在运行的 iOS 版本。
  • @shallowThought 根本不起作用,所有版本都包括 ios 10
  • 任何人都可以帮助解决这个问题

标签: ios swift swift3 uilocalnotification localnotification


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2014-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-29
    • 2018-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多