代码之家  ›  专栏  ›  技术社区  ›  cdub

未在swift 4中调用didReceiveRemoteNotifications的本地通知[副本]

  •  0
  • cdub  · 技术社区  · 6 年前

    我有以下appDelegate:

    import UIKit
    import CoreData
    import UserNotifications
    
    @available(iOS 11.0, *)
    @UIApplicationMain
    class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate
    {
        var window: UIWindow?
    
        ...
    
        func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any])
        {
            print("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
        }
    }
    

    我正在使用ios11和swift 4.1,但通知被正确触发。但当我点击它时,我无法在应用程序中抓取它为什么?我正在使用xcode 9.4.1。谢谢。

    应用程序在后台,当点击通知时,应用程序将打开。

    1 回复  |  直到 6 年前
        1
  •  2
  •   Sandip Gill    6 年前

    您好@cdub您应该使用usernotificationocenter

     func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
    
        // do code here to show notification alert in for-ground mode 
    }
    
    
    
    
    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
        //your notification handling code here 
        }