当通知即将到来时,didReceiveRemoteNotification方法未调用

时间:2018-08-24 08:28:32

标签: ios swift push-notification apple-push-notifications ios11

我不明白为什么我的代码无法正常工作。

我的代码是

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void)

{

    print("User Info = ",userInfo)

    NotificationCenter.default.post(name: NSNotification.Name(rawValue: "reloadChatTableView"), object: nil)

    GlobalConstant.notificationDict = userInfo

    let notificationDictionary: NSDictionary = GlobalConstant.notificationDict?["aps"] as! NSDictionary

    let type: String = Global.getStringValue(notificationDictionary.value(forKey: "type") as AnyObject)

    //   application.applicationIconBadgeNumber = application.applicationIconBadgeNumber + 1

completionHandler(UIBackgroundFetchResult.noData)

var aps: [AnyHashable: Any] = userInfo["aps"] as! [AnyHashable : Any]

        //content.sound = UNNotificationSound.init(named: "tone.mp3")

        let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1, repeats: false)

        let request = UNNotificationRequest(identifier: "timerDone", content: content, trigger: trigger)

        UNUserNotificationCenter.current().add(request, withCompletionHandler: nil
}

0 个答案:

没有答案