thebergamo / react-native-fbsdk-next

MIT License
663 stars 164 forks source link

App ID not found (iOS) #56

Closed Deodes closed 3 years ago

Deodes commented 3 years ago

🐛 Bug Report

After LoginManager.logInWithPermissions() catch an error on iOS:

Снимок экрана 2021-06-16 в 14 13 00

To Reproduce

Followed the documentation, and get into this error. Also cannot understand if i edited AppDelegate.m correctly?

Expected Behavior

Open facebook modal for sign in

Code Example

All files involved:

AppDelegate.m

#import <Firebase.h>
#import "AppDelegate.h"

#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>

#ifdef FB_SONARKIT_ENABLED
#import <FlipperKit/FlipperClient.h>
#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
#import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
#import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>
#import <FlipperKitReactPlugin/FlipperKitReactPlugin.h>

#import <FBSDKCoreKit/FBSDKCoreKit.h>

static void InitializeFlipper(UIApplication *application) {
  FlipperClient *client = [FlipperClient sharedClient];
  SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults];
  [client addPlugin:[[FlipperKitLayoutPlugin alloc] initWithRootNode:application withDescriptorMapper:layoutDescriptorMapper]];
  [client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]];
  [client addPlugin:[FlipperKitReactPlugin new]];
  [client addPlugin:[[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]];
  [client start];
}
#endif

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  [FBSDKApplicationDelegate initializeSDK:launchOptions]; //<-- FacebookSDK initialize

  if ([FIRApp defaultApp] == nil) { // <-- Firebase iOS SDK must be configured during the bootstrap phase of your application
    [FIRApp configure];
  }

  #ifdef FB_SONARKIT_ENABLED
    InitializeFlipper(application);
  #endif

  [[FBSDKApplicationDelegate sharedInstance] application:application // <-- Connect App Delegate
                           didFinishLaunchingWithOptions:launchOptions]; 

  RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
  RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
                                                   moduleName:@"MeQRReviewApp"
                                            initialProperties:nil];

  if (@available(iOS 13.0, *)) {
      rootView.backgroundColor = [UIColor systemBackgroundColor];
  } else {
      rootView.backgroundColor = [UIColor whiteColor];
  }

  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [UIViewController new];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];

  return YES;
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
  return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}

- (BOOL)application:(UIApplication *)application // <-- Connect App Delegate
            openURL:(NSURL *)url
            options:(nonnull NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options
{
  [[FBSDKApplicationDelegate sharedInstance] application:application
                                                 openURL:url
                                                 options:options];
  return YES;
}

@end

Info.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleDevelopmentRegion</key>
    <string>en</string>
    <key>CFBundleDisplayName</key>
    <string>MeQRReviewApp</string>
    <key>CFBundleExecutable</key>
    <string>$(EXECUTABLE_NAME)</string>
    <key>CFBundleIdentifier</key>
    <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>$(PRODUCT_NAME)</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>1.0</string>
    <key>CFBundleSignature</key>
    <string>????</string>
    <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleTypeRole</key>
            <string>Editor</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>XXX</string>
            </array>
        </dict>
    </array>
    <key>CFBundleVersion</key>
    <string>1</string>
    <key>LSRequiresIPhoneOS</key>
    <true/>
    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSExceptionDomains</key>
        <dict>
            <key>localhost</key>
            <dict>
                <key>NSExceptionAllowsInsecureHTTPLoads</key>
                <true/>
            </dict>
        </dict>
        <key>CFBundleURLTypes</key>
        <array>
            <dict>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>fbXXX</string>
            </array>
            </dict>
        </array>
        <key>FacebookAppID</key>
        <string>XXX</string>
        <key>FacebookClientToken</key>
        <string>XXX</string>
        <key>FacebookDisplayName</key>
        <string>XXX</string>
        <key>LSApplicationQueriesSchemes</key>
        <array>
            <string>fbapi</string>
            <string>fbapi20130214</string>
            <string>fbapi20130410</string>
            <string>fbapi20130702</string>
            <string>fbapi20131010</string>
            <string>fbapi20131219</string>
            <string>fbapi20140410</string>
            <string>fbapi20140116</string>
            <string>fbapi20150313</string>
            <string>fbapi20150629</string>
            <string>fbapi20160328</string>
            <string>fbauth</string>
            <string>fb-messenger-share-api</string>
            <string>fbauth2</string>
            <string>fbshareextension</string>
        </array>
    </dict>
    <key>NSLocationWhenInUseUsageDescription</key>
    <string></string>
    <key>UIAppFonts</key>
    <array>
        <string>AntDesign.ttf</string>
        <string>Entypo.ttf</string>
        <string>EvilIcons.ttf</string>
        <string>Feather.ttf</string>
        <string>FontAwesome.ttf</string>
        <string>FontAwesome5_Brands.ttf</string>
        <string>FontAwesome5_Regular.ttf</string>
        <string>FontAwesome5_Solid.ttf</string>
        <string>Foundation.ttf</string>
        <string>Ionicons.ttf</string>
        <string>MaterialIcons.ttf</string>
        <string>MaterialCommunityIcons.ttf</string>
        <string>SimpleLineIcons.ttf</string>
        <string>Octicons.ttf</string>
        <string>Zocial.ttf</string>
        <string>Fontisto.ttf</string>
    </array>
    <key>UILaunchStoryboardName</key>
    <string>LaunchScreen</string>
    <key>UIRequiredDeviceCapabilities</key>
    <array>
        <string>armv7</string>
    </array>
    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    <key>UIViewControllerBasedStatusBarAppearance</key>
    <false/>
</dict>
</plist>

Environment

React Native: 0.64.2 react-native-fbsdk-next: 4.3.0

mikehardy commented 3 years ago

That looks like a pretty thorough error message. How did it go when you added the app id to info.plist ?

Deodes commented 3 years ago

@mikehardy as in the error picture (I'm just hiding the app IDs, but they are correct, double checked), and this issue just on iOS, Android works well. Maybe I should show the entire error code?

mikehardy commented 3 years ago

I don't know. Perhaps something about the build system means your not running the code you think you're running? 'npx react-native-clean-project'?

biztems commented 3 years ago

Same issue here.

mikehardy commented 3 years ago

For anyone else paying attention: this is not a universal problem. Works fine for me :shrug: not sure what the problem is but the module appears to work.

biztems commented 3 years ago

We came from a previous version of the SDK (it was actually before FB deprecated it so we weren't using next yet) and as such we were missing the SDK initialization steps.

@Deodes https://github.com/thebergamo/react-native-fbsdk-next#sdk-initialization

mikehardy commented 3 years ago

But...it's explicit in the docs here that you must initialize the SDK on iOS now? I am definitely doing that in my project, is that common amongst the people crashing here - that you are not initializing?

https://github.com/thebergamo/react-native-fbsdk-next#sdk-initialization

Deodes commented 3 years ago

@mikehardy @biztems added native facebookSDK initialization (AppDelegate.m), but still have the same problem. Maybe we need to compare our "AppDelegate.m" files?

Deodes commented 3 years ago

Solved a problem. Everything that was in the AppDelagate.m file should have been at the top level inside <dict></dict>, in my case it was inside nested<dict></dict>