首页 > 解决方案 > 通知到来时没有调用 didReceiveRemoteNotification 方法

问题描述

我不明白为什么我的代码不起作用。

我的代码是

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
}

标签: iosswiftpush-notificationapple-push-notificationsios11

解决方案


推荐阅读