React Native Facebook 登录和分支 AppDelegate
Posted
技术标签:
【中文标题】React Native Facebook 登录和分支 AppDelegate【英文标题】:React Native Facebook Login and Branch AppDelegate 【发布时间】:2018-12-24 04:59:45 【问题描述】:我正在尝试为我的 react 本机应用程序设置 facebook 登录和分支深度链接。单独我可以让它们正常工作,但我无法让它们在 ios 中一起工作。
我认为问题出在 AppDelegate.m
Facebook 登录 (react-native-facebook-login) 需要:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
// ...
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = [[UIViewController alloc] init];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
// return YES;
return [[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
- (void)applicationDidBecomeActive:(UIApplication *)application
[FBSDKAppEvents activateApp];
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation];
分支(react-native-branch-deep-linking)需要:
// Initialize the Branch Session at the top of existing application:didFinishLaunchingWithOptions:
func application(_ application: UIApplication, didFinishLaunchingWithOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool
// Uncomment this line to use the test key instead of the live one.
// RNBranch.useTestInstance()
RNBranch.initSession(launchOptions: launchOptions, isReferrable: true) // <-- add this
//...
// Add the openURL and continueUserActivity functions
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool
return RNBranch.branch.application(app, open: url, options: options)
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool
return RNBranch.continue(userActivity)
【问题讨论】:
【参考方案1】:试试下面的代码:
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation] ||
RNBranch.branch.application(app, open: url, options: options)
【讨论】:
以上是关于React Native Facebook 登录和分支 AppDelegate的主要内容,如果未能解决你的问题,请参考以下文章
React-Native:Facebook 登录后返回应用程序?
react-native如何在facebook登录和注销后刷新页面
如何在 React Native 中进行 Facebook 登录?
在 React Native 组件中使用 Facebook 登录功能