firebase ios大部分时间不工作

firebase ios大部分时间不工作,ios,swift,firebase,Ios,Swift,Firebase,我刚刚在ios应用程序swift 3上安装了firebase。问题是,有时通知从未送达,有时它运行良好,但我从未更改AppDelegate中的代码。你建议我编辑什么,我找不到问题 注:如果我使用应用程序,我不会收到通知,只有当我不使用应用程序时,我才会收到通知,为什么 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunc

我刚刚在ios应用程序swift 3上安装了firebase。问题是,有时通知从未送达,有时它运行良好,但我从未更改AppDelegate中的代码。你建议我编辑什么,我找不到问题

注:如果我使用应用程序,我不会收到通知,只有当我不使用应用程序时,我才会收到通知,为什么

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    // Override point for customization after application launch.

    let lagFreeField = UITextField()
    self.window?.addSubview(lagFreeField)
    lagFreeField.becomeFirstResponder()
    lagFreeField.resignFirstResponder()
    lagFreeField.removeFromSuperview()


    // [START register_for_notifications]
    if #available(iOS 10.0, *) {
        let authOptions : UNAuthorizationOptions = [.alert, .badge, .sound]
        UNUserNotificationCenter.current().requestAuthorization(
            options: authOptions, completionHandler: {_,_ in })

        // For iOS 10 display notification (sent via APNS)
        UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
        // For iOS 10 data message (sent via FCM)
        FIRMessaging.messaging().remoteMessageDelegate = self as? FIRMessagingDelegate

    } else {
        let settings = UIUserNotificationSettings(types: [.alert, .badge , .sound], categories: nil)

        application.registerUserNotificationSettings(settings)
        application.registerForRemoteNotifications()
    }

    application.registerForRemoteNotifications()

    // [END register_for_notifications]

    FIRApp.configure()

    print("AppDelegate")

   IQKeyboardManager.sharedManager().enable = true
    self.window = UIWindow(frame: UIScreen.main.bounds)
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let tab = storyboard.instantiateViewController(withIdentifier: "TabBarController") as! UITabBarController
    self.window?.rootViewController = tab
    if Defaults.hasKey(.logged), let logged = Defaults[.logged], logged == true{
        APIRequest.username = Defaults[.username]!
        APIRequest.password = Defaults[.password]!
        let tab = storyboard.instantiateViewController(withIdentifier: "TabBarController") as! UITabBarController
        self.window?.rootViewController = tab

    } else {
        let controller = storyboard.instantiateViewController(withIdentifier: "LoginViewController")
        self.window?.rootViewController = controller
    }
    self.window?.makeKeyAndVisible()

    return true
}

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
    print("Userinfo \(userInfo)")
}

只需按照firebase说明中的步骤操作即可。Firebase说明:

AppCoda还撰写了另一篇将firebase推送通知从零开始安装到live应用程序的精彩文章:


首先,在使用
FIRApp.configure()成功配置库之前,您需要调用
FIRMessaging
。我会更早地移动配置行,这可能会消除您的一些问题…如果您想在注销时关闭firebase推送通知-注销,请使用:UIApplication.sharedApplication().unregisterForRemoteNotifications()--在登录时重新启用它:UIApplication.sharedApplication().RegisterForRemotonifications()