代码之家  ›  专栏  ›  技术社区  ›  NicholasByDesign

iOS React Native Firebase(Invertase)Google登录构建失败

  •  1
  • NicholasByDesign  · 技术社区  · 7 年前

    我一直试图通过 inverstase 包装。我已经按照文档的顺序阅读了它,并按照其他各种顺序,比如从SDK开始

    1. https://rnfirebase.io/docs/v4.3.x/auth/social-auth#Google
    2. https://github.com/react-native-community/react-native-google-signin
    3. https://github.com/react-native-community/react-native-google-signin/blob/master/ios-guide.md

    我的项目设置如下所示:

    播客文件

    # Uncomment the next line to define a global platform for your project
    # platform :ios, '9.0'
    
    target 'giftdrop' do
      ### GOOGLE MAPS ###
      rn_path = '../node_modules/react-native'
      rn_maps_path = '../node_modules/react-native-maps'
    
      # See http://facebook.github.io/react-native/docs/integration-with-existing-apps.html#configuring-cocoapods-dependencies
      pod 'yoga', path: "#{rn_path}/ReactCommon/yoga/yoga.podspec"
      pod 'React', path: rn_path, subspecs: [
        'Core',
        'CxxBridge',
        'DevSupport',
        'RCTActionSheet',
        'RCTAnimation',
        'RCTGeolocation',
        'RCTImage',
        'RCTLinkingIOS',
        'RCTNetwork',
        'RCTSettings',
        'RCTText',
        'RCTVibration',
        'RCTWebSocket',
      ]
    
      # React Native third party dependencies podspecs
      pod 'DoubleConversion', :podspec => "#{rn_path}/third-party-podspecs/DoubleConversion.podspec"
      pod 'glog', :podspec => "#{rn_path}/third-party-podspecs/glog.podspec"
      # If you are using React Native <0.54, you will get the following error:
      # "The name of the given podspec `GLog` doesn't match the expected one `glog`"
      # Use the following line instead:
      #pod 'GLog', :podspec => "#{rn_path}/third-party-podspecs/GLog.podspec"
      pod 'Folly', :podspec => "#{rn_path}/third-party-podspecs/Folly.podspec"
    
      # react-native-maps dependencies
      pod 'react-native-maps', path: rn_maps_path
      pod 'react-native-google-maps', path: rn_maps_path  # Remove this line if you don't want to support GoogleMaps on iOS
      pod 'GoogleMaps'  # Remove this line if you don't want to support GoogleMaps on iOS
      pod 'Google-Maps-iOS-Utils' # Remove this line if you don't want to support GoogleMaps on iOS
    
      ### FIREBASE ###
      pod 'Firebase/Core'
      pod 'Firebase/Firestore'
      pod 'Firebase/Auth'
      pod 'RNShare', :path => '../node_modules/react-native-share'
      pod 'Firebase/Messaging'
    
      pod 'react-native-version-number', :path => '../node_modules/react-native-version-number'
    
      pod 'GoogleSignIn'
    
      pod 'RNGoogleSignin', :path => '../node_modules/react-native-google-signin'
    
    end
    
    post_install do |installer|
      installer.pods_project.targets.each do |target|
        if target.name == 'react-native-google-maps'
          target.build_configurations.each do |config|
            config.build_settings['CLANG_ENABLE_MODULES'] = 'No'
          end
        end
        if target.name == "React"
          target.remove_from_project
        end
      end
    end
    

    应用委托.m

    #import "AppDelegate.h"
    #import <Fabric/Fabric.h>
    #import <Crashlytics/Crashlytics.h>
    #import <React/RCTBundleURLProvider.h>
    #import <React/RCTRootView.h>
    #import <React/RCTLinkingManager.h>
    #import <Firebase.h>
    #import <React/RCTPushNotificationManager.h> // NPM module Notifications
    #import "RNFirebaseNotifications.h" // Firebase Notifications
    #import "RNFirebaseMessaging.h" // Firebase remote Notifications
    #import <FBSDKCoreKit/FBSDKCoreKit.h>
    #import "RNGoogleSignin.h"
    @import GoogleMaps;
    
    @implementation AppDelegate
    
    - (void)applicationDidBecomeActive:(UIApplication *)application {
      [FBSDKAppEvents activateApp];
    }
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
      [FIRApp configure];
      [[FBSDKApplicationDelegate sharedInstance] application:application
        didFinishLaunchingWithOptions:launchOptions];
    
      NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
      if (![defaults boolForKey:@"notFirstRun"]) {
        [defaults setBool:YES forKey:@"notFirstRun"];
        [defaults synchronize];
        [[FIRAuth auth] signOut:NULL];
      }
    
      [RNFirebaseNotifications configure]; // Firebase Notifications
      NSURL *jsCodeLocation;
      [GMSServices provideAPIKey:@"AIzaSyDLSohfIWoBOSmzpAHUqDSL-puku7LDP6U"];
    
      jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
    
      RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                          moduleName:@"giftdrop"
                                                   initialProperties:nil
                                                       launchOptions:launchOptions];
      rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
    
      self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
      UIViewController *rootViewController = [UIViewController new];
      rootViewController.view = rootView;
      self.window.rootViewController = rootViewController;
      [self.window makeKeyAndVisible];
      [Fabric with:@[[Crashlytics class]]];
    
      return YES;
    }
    // deeplinking for fb and normal
    - (BOOL)application:(UIApplication *)application 
                openURL:(NSURL *)url
                options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
                sourceApplication:(NSString *)sourceApplication 
                annotation:(id)annotation {
    
    
      BOOL handled = [[FBSDKApplicationDelegate sharedInstance] application:application
                                                            openURL:url
                                                  sourceApplication:sourceApplication
                                                         annotation:annotation
             ]
             || [RNGoogleSignin application:application
                                    openURL:url
                          sourceApplication:sourceApplication
                                 annotation:annotation
                ];
    
      return handled || [RCTLinkingManager application:application openURL:url
                          sourceApplication:sourceApplication annotation:annotation];
    }
    
     // Required for the register event.
     - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
     {
      [RCTPushNotificationManager didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
     }
    
     // Required for the registrationError event.
     - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
     {
      [RCTPushNotificationManager didFailToRegisterForRemoteNotificationsWithError:error];
     }
     // Required for the localNotification event.
     - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
     {
      [RCTPushNotificationManager didReceiveLocalNotification:notification];
     }
    
     - (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo
                                                           fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler{
      [[RNFirebaseNotifications instance] didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
    }
    
    - (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
      [[RNFirebaseMessaging instance] didRegisterUserNotificationSettings:notificationSettings];
    }
    
    
    @end
    

    框架 enter image description here

    URL类型 为了安全起见,我更改了字符串,但我是从GoogleInfo.plist REVERSED_CLIENT_ID获得的 enter image description here

    链接库 enter image description here

    框架搜索路径 根据文档添加的字符串被添加到release和debug中

    enter image description here

    Firebase本身工作得很好,Facebook的SDK也一样,但是不管我怎么做,我的项目都无法构建,错误很多,这取决于我做事情的顺序。

    最常见的是CFBundler错误,重复库,有时根本没有错误只是构建失败

    更新 似乎Xcode正在报告“RNGoogleSignin.h”导入未找到

    1 回复  |  直到 7 年前
        1
  •  1
  •   NicholasByDesign    7 年前

    我不得不手动链接项目及其库来解决这个问题,如这里的文档所示 https://github.com/react-native-community/react-native-google-signin

    其次,我还必须 #import "RNGoogleSignin.h" 作为 #import <GoogleSignIn/GoogleSignIn.h> 与文件不同。

    推荐文章