Firebase推送通知不起作用iOS11 Swift 4.1

时间:2018-08-08 15:46:19

标签: ios swift firebase push-notification cocoapods

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

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

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

我还激活了通知功能: enter image description here enter image description here

我在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框架添加到我的项目中,或者解决该问题的必要步骤是什么?

谢谢。

1 个答案:

答案 0 :(得分:0)

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

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