React-native-fbsdk: How to Connect the App Delegate?

Created on 24 Jun 2020  路  6Comments  路  Source: facebook/react-native-fbsdk

Need Help/Question

Hi, i'm trying to connect the app delegate following the Step 3: Connect the App Delegate

I couldn't find the AppDelegate.swift file.

Am I supposed to override theAppDelegate.m file with the following code?

//  AppDelegate.swift

import UIKit
import FBSDKCoreKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

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

        ApplicationDelegate.shared.application(
            application,
            didFinishLaunchingWithOptions: launchOptions
        )

        return true
    }

    func application(
        _ app: UIApplication,
        open url: URL,
        options: [UIApplication.OpenURLOptionsKey : Any] = [:]
    ) -> Bool {

        ApplicationDelegate.shared.application(
            app,
            open: url,
            sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
            annotation: options[UIApplication.OpenURLOptionsKey.annotation]
        )

    }  

}

Most helpful comment

this is my updated code in AppDelegate.m
You need to import
#import <FBSDKCoreKit/FBSDKCoreKit.h>

Then update openURL method

- (BOOL)application:(UIApplication *)application
   openURL:(NSURL *)url
   options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
  if ([[FBSDKApplicationDelegate sharedInstance] application:application
                                                      openURL:url
                                                      options:options]) {
     return YES;
  }
  return [RCTLinkingManager application:application openURL:url options:options];
}

All 6 comments

@TamashiKaizen I'm facing the same issue, instructions are not clear enough.

same issue. I don't have appdelegate.swift in my ios project

Same issue. Web login is working but since react native project using objective c, I can't able to adopt new SceneDelegate changes. It's not working in iOS 13

this is my updated code in AppDelegate.m
You need to import
#import <FBSDKCoreKit/FBSDKCoreKit.h>

Then update openURL method

- (BOOL)application:(UIApplication *)application
   openURL:(NSURL *)url
   options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
  if ([[FBSDKApplicationDelegate sharedInstance] application:application
                                                      openURL:url
                                                      options:options]) {
     return YES;
  }
  return [RCTLinkingManager application:application openURL:url options:options];
}

I had some code in my AppDelegate and due to it, It was not working

Not working code:

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
    if ([RNBranch application:app openURL:url options:options])  {
        // do other deep link routing for the Facebook SDK, Pinterest SDK, etc
        if ([[FBSDKApplicationDelegate sharedInstance] application:app openURL:url options:options]) {
           return YES;
        }

        if ([RCTLinkingManager application:app openURL:url options:options]){
           return YES;
        }
    }
    return YES;
}

Working code:

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
    if ([[FBSDKApplicationDelegate sharedInstance] application:app openURL:url options:options]) {
        return YES;
    } 
    if ([RNBranch application:app openURL:url options:options])  {
        // do other deep link routing for the Facebook SDK, Pinterest SDK, etc
        if ([RCTLinkingManager application:app openURL:url options:options]){
           return YES;
        }
    }
    return YES;
}
Was this page helpful?
0 / 5 - 0 ratings