如何在 App Delegate 中使用 Firebase 配置 Pusher Beams SDK?

How to configure Pusher Beams SDK with Firebase in App Delegate?

我的后端项目中有 Firebase SDK,我正在使用 Pusher 的 Beams SDK 配置推送通知。

问题是,如果我有 Firebase,我的应用程序委托似乎没有配置我需要使用 Beams SDK 发送通知的设置。这就是我的意思。

根据 Beams SDK,我需要将这段代码放在 didFinishLaunchingWithOptions

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
    
    self.pushNotifications.start(instanceId: "MyInstanceID")
        self.pushNotifications.registerForRemoteNotifications()
        try? self.pushNotifications.addDeviceInterest(interest: "debug-hello")
   // FirebaseApp.configure() . However it ONLY works properly when this is commented out
    
    
    
    return true
}

如上所示,如果我注释掉 Firebase 配置,它只会正确配置我的通知。这是我的委托中的其他相关代码:


func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        
        print("RECEIVED NOTIFICATION")
        self.pushNotifications.handleNotification(userInfo: userInfo)
   
       
        
        if Auth.auth().canHandleNotification(userInfo){
            completionHandler(.noData)
            return
        }
        
        
    }


func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        print("Did register for remote notifications")
        self.pushNotifications.registerDeviceToken(deviceToken)
        Auth.auth().setAPNSToken(deviceToken, type: .prod)
        

    }

如何在我的项目中正确配置两者?

问题是 Firebase.configure() 会破坏 didRegisterForRemoteNotificationsWithDeviceToken 方法。

您需要将 GoogleUtilitiesAppDelegateProxyEnabled 添加到 info.plist 并将其设置为 NO