react-native-twitter-signin - It does not work with the native Twitter app on Iphone

Viewed 293

I am using react-native-twitter-signin to implement authentication with twitter in my app, but there is a detail, in iOS (iphone) at the time of login if you have the twitter app installed, it is activated and after authorize the access of my application, the WebView is displayed in the same way to add the credentials, after this the login process runs without problems and I can get the answer.

In some cases I can see in the xcode console errors like "Error getting user token", this happens in the native twitter application.

In android it works without problem, both in webview and in the native twitter application. From my point of view, the webview is activated if the twitter application is not installed. I appreciate suggestions.

https://github.com/GoldenOwlAsia/react-native-twitter-signin

AppDelegate.m

#import "AppDelegate.h"
#import "RNBootSplash.h" // <- add the bootsplash

#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <FBSDKCoreKit/FBSDKCoreKit.h> // <- add the Facebook FBSDK
#import <React/RCTLinkingManager.h> // <- Add This Import
#import <Firebase.h>
#import <TwitterKit/TWTRKit.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>

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
{
    [FIRApp configure];

#ifdef FB_SONARKIT_ENABLED
  InitializeFlipper(application);
#endif
  
  [[FBSDKApplicationDelegate sharedInstance] application:application
                           didFinishLaunchingWithOptions:launchOptions];

  RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
  RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
                                                   moduleName:@"my-app"
                                            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];

  [RNBootSplash initWithStoryboard:@"BootSplash" rootView:rootView]; // <- initialization using the storyboard file name
  
  return YES;
}

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

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

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

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

@end

login.js

const loginWithTwitter = () => {
    RNTwitterSignIn.init(
      APIKEY.TWITTER_COMSUMER_KEY,
      APIKEY.TWITTER_CONSUMER_SECRET,
    )

    RNTwitterSignIn.logIn()
      .then(loginData => {
        const {authToken, authTokenSecret} = loginData;
        console.log(authToken, authTokenSecret);
      })
      .catch(error => {
        console.log('ERROR:', error);
      });
  };
0 Answers
Related