facebookarchive / react-native-fbsdk

A React Native wrapper around the Facebook SDKs for Android and iOS. Provides access to Facebook login, sharing, graph requests, app events etc.
https://developers.facebook.com/docs/react-native
Other
2.99k stars 909 forks source link

How to Connect the App Delegate? #770

Open KaizenTamashi opened 4 years ago

KaizenTamashi commented 4 years ago

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]
        )

    }  

}
ianvasco commented 4 years ago

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

hakkikonu commented 4 years ago

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

joypatel04 commented 4 years ago

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

OscarYuen commented 4 years ago

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];
}
raibima commented 4 years ago

see the example app here https://github.com/facebook/react-native-fbsdk/blob/master/example/ios/RNFBSDKExample/AppDelegate.m

joypatel04 commented 4 years ago

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;
}