【问题标题】:Firebase Push notifications not working ios11 swift 4.1Firebase推送通知不起作用ios11 swift 4.1
【发布时间】:2018-08-08 15:46:18
【问题描述】:

更新我的手机并重新安装应用程序后,我注意到推送通知是通过remoteMessage 方法而不是didReceiveRemoteNotification 方法。 更新 firebase 后,名为nanopb 的框架消失了,当我尝试构建项目时,我面临着 ld: framework not found nanopb clang: error: linker command failed with exit code 1 (use -v to see invocation) 我尝试像这样设置 pod:

pod 'Firebase/Core', '4.0.3'
pod 'Firebase/Messaging', '4.0.3'
pod 'FirebaseInstanceID', '2.0.0'

根据this answer,我试过了,但出现同样的“未找到”错误。

我还激活了通知功能:

我在 appDelegate 中的代码是:

let gcmMessageIDKey         = "gcm.message_id"

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    UIApplication.shared.statusBarStyle = .lightContent

    FirebaseApp.configure()
    Messaging.messaging().delegate = self
    Messaging.messaging().shouldEstablishDirectChannel = true

    if #available(iOS 10.0, *) {
        UNUserNotificationCenter.current().delegate = self
        let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
        UNUserNotificationCenter.current().requestAuthorization(
            options: authOptions,
            completionHandler: {_, _ in })
    }else {
        let settings: UIUserNotificationSettings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
        application.registerUserNotificationSettings(settings)
    }

    application.registerForRemoteNotifications()
    NotificationCenter.default.addObserver(self, selector: #selector(self.tokenRefreshNotification), name: .InstanceIDTokenRefresh, object: nil)



    if let token = Messaging.messaging().fcmToken{
        print("FCM token: \(token)")
    } else {
        //will refresh in some method for later
    }
    return true
}


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

    if let messageID = userInfo[gcmMessageIDKey] {
        print("Message ID: \(messageID)")
    }

    completionHandler(UIBackgroundFetchResult.newData)
}

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

}

有一种方法可以将 nanopb 框架添加到我的项目中,或者解决此问题的必要步骤是什么?

谢谢。

【问题讨论】:

    标签: ios swift firebase push-notification cocoapods


    【解决方案1】:

    我今天打开了我的应用程序,它又可以工作了...

    显然这是 firebase 的问题...我所有其他应用一整天都没有收到任何推送通知。

    【讨论】:

    • 对于 Firebase 4.0.3+ 没有使用 nanopod 框架,然后将其删除。
    • 我现在也有同样的问题。推送通知在早些时候工作,今天无法让他们工作!说真的,我不明白出了什么问题!
    猜你喜欢
    • 2017-04-29
    • 1970-01-01
    • 1970-01-01
    • 2020-06-11
    • 1970-01-01
    • 1970-01-01
    • 2017-10-10
    • 1970-01-01
    相关资源
    最近更新 更多