【问题标题】:SwiftUI and Firebase: Get Info from push notificationsSwiftUI 和 Firebase:从推送通知中获取信息
【发布时间】:2021-04-27 19:49:42
【问题描述】:

我想将来自Firebasepush notifications 接收到我的SwiftUI 的应用程序中。 我可以看到我的通知并且效果很好,但我不知道如何处理操作值来处理数据。我读到了didReceiveRemoteNotification,但没有用。你知道我做错了什么吗?

非常感谢...

AppDelegate.swift

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
    
    if let messageID = userInfo[gcmMessageIDKey] {
        print("Message ID: \(messageID)")
    }
  
    print(userInfo)
}

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
                 fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
    
    if let messageID = userInfo[gcmMessageIDKey] {
        print("Message ID: \(messageID)")
    }
    
    print(userInfo)
    
    
    completionHandler(UIBackgroundFetchResult.newData)
}

【问题讨论】:

    标签: firebase push-notification swiftui apple-push-notifications


    【解决方案1】:

    这解决了我的生活:

    extension AppDelegate: UNUserNotificationCenterDelegate {
        
        func userNotificationCenter(_ center: UNUserNotificationCenter,
                                    didReceive response: UNNotificationResponse,
                                    withCompletionHandler completionHandler: @escaping () -> Void) {
            
            let userInfo = response.notification.request.content.userInfo
            let url = userInfo["url"] as! String
            
            print(url)
            
            completionHandler()
        }
    }
    

    【讨论】:

    • 非常酷,伙计。我不禁注意到您说您的应用仍在接收推送通知。自从 Apple 停止支持旧版端口 2195 和 2196 以来,尚未为 APNS 实施正确网络管理步骤的开发人员,您能否为我们其他人指出正确的方向?
    猜你喜欢
    • 1970-01-01
    • 2021-02-06
    • 1970-01-01
    • 2020-06-05
    • 2016-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-13
    相关资源
    最近更新 更多