如何在Xcode中导入Firebase

时间:2019-04-01 10:17:26

标签: ios bash macos flutter xcode10

我一直在尝试将flearbase添加到我的flutter应用程序中,但是在此之前,我必须先转到Xcode并添加一些内容以便能够为iOS钩连firebase。我已经尝试了导入语句,但是没有用。该代码是Dart代码。

#include "AppDelegate.h"
#include "GeneratedPluginRegistrant.h"

import Firebase;

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  [GeneratedPluginRegistrant registerWithRegistry:self];
  // Override point for customization after application launch.
  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
override init() {
    FIRApp.configure()
    FIRDatabase.database().persistenceEnabled = true
}

@end

This what I added and did not work and also the import did not work

override init() {
    FIRApp.configure()
    FIRDatabase.database().persistenceEnabled = true
}

2 个答案:

答案 0 :(得分:0)

假设您使用CocoaPod作为依赖项管理器。

  1. 可选(如果尚未使用cocoapods)
      

    pod初始化

  2. 将Firebase添加到podfile中并运行pod install。
      

    pod“ Firebase / Core”

  3. 打开工作区而不是项目。并尝试导入框架。

现在应该可以使用。

Firebase official documentation

答案 1 :(得分:0)

您唯一需要做的就是将firebase plist文件GoogleService-Info.plist放在ios/Runner文件夹中。将Firebase依赖项添加到您的pubspec.yaml文件中,然后运行flutter packages get,这将为您安装依赖项并运行pod install。如果您过去曾在IOS中使用过Firebase,并且没有进行更新,那么也许可以使用pod update Firebase

来更新它的pod版本。

请记住,此后请完全重新启动您的应用。

还要确保在https://firebase.google.com/docs/flutter/setup

处阅读此信息