2016-04-28 2 views
0

J'essaye de faire fonctionner le FBSDK dans un projet iOS ReactNative.Obtenir ReactNative FacebookSDK fonctionnant

Je react-native init AwesomeProject pour obtenir un tout nouveau projet, suivez les React Native FBSDK instructions sur GitHub, et je reçois une erreur dans main.m:

thread 1:signal SIGABRT 

Un peu googler me conduit here alors here qui m'a ajouter une clé LSApplicationQueriesSchemes à mon info.plist. Résoudre ce problème.

Je suis ensuite le Facebook app setup guide qui m'a ajouté, entre autres, une clé NSAppTransportSecurity à mon info.plist`. Mais l'application ne peut pas se connecter au serveur de développement.

Un peu plus de googler et je trouve this page qui dit que je n'ai pas besoin de la clé NSAppTransportSecurity alors je l'enlève et l'application fonctionne. Ouf, problème résolu.

Retour dans le React Native FBSDK github page, je prends le premier exemple dans leur section d'utilisation; le LoginButton. Copiez-le mot pour mot dans mon application. Ça fonctionne. Je clique dessus Et ...

thread 1:signal SIGABRT 

Aaaah!

Quelqu'un at-il obtenu ce travail?

Répondre

2

Je l'ai! Après l'installation du SDK, vous devez vous assurer que toutes les configurations sont définies. Vous devez également importer le fichier SDK dans votre AppDelegate.

Voici les configs pertinentes de mon info.plist.

<key>CFBundleURLTypes</key> 
    <array> 
    <dict> 
     <key>CFBundleURLSchemes</key> 
     <array> 
     <string>fb12345678910</string> 
     </array> 
    </dict> 
    </array> 
    <key>FacebookAppID</key> 
    <string>12345678910</string> 
    <key>FacebookDisplayName</key> 
    <string>My Awesome App</string> 


    <key>NSAppTransportSecurity</key> 
    <dict> 
    <key>NSExceptionDomains</key> 
    <dict> 
     <key>facebook.com</key> 
     <dict> 
     <key>NSIncludesSubdomains</key> <true/> 
     <key>NSThirdPartyExceptionRequiresForwardSecrecy</key> <false/> 
     </dict> 
     <key>fbcdn.net</key> 
     <dict> 
     <key>NSIncludesSubdomains</key> <true/> 
     <key>NSThirdPartyExceptionRequiresForwardSecrecy</key> <false/> 
     </dict> 
     <key>akamaihd.net</key> 
     <dict> 
     <key>NSIncludesSubdomains</key> <true/> 
     <key>NSThirdPartyExceptionRequiresForwardSecrecy</key> <false/> 
     </dict> 
     <key>localhost</key> 
     <dict> 
     <key>NSExceptionAllowsInsecureHTTPLoads</key> <true/> 
     </dict> 
     <key>api.mydomain.com</key> 
     <dict> 
     <key>NSExceptionAllowsInsecureHTTPLoads</key> <true/> 
     </dict> 
    </dict> 
    </dict> 


    <key>LSApplicationQueriesSchemes</key> 
    <array> 
    <string>fbapi</string> 
    <string>fb-messenger-api</string> 
    <string>fbauth2</string> 
    <string>fbshareextension</string> 
    </array> 

Il y a trois sections:

  1. Vous devez définir votre App Id et le nom d'affichage.
  2. Vous devez définir les domaines que votre application aura accès, évidemment les domaines de facebook, akamai et vos propres domaines, j'ai inclus localhost à la liste.
  3. Enfin, vous devez inclure les schémas de requête

Voici mon dossier AppDelegate.m.

`` ` #import "AppDelegate.h"

#import "RCTRootView.h" 

#import <FBSDKCoreKit/FBSDKCoreKit.h> 

@implementation AppDelegate 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    NSURL *jsCodeLocation; 

    /** 
    * Facebook SDK 
    * 
    **/ 
    [[FBSDKApplicationDelegate sharedInstance] application:application 
          didFinishLaunchingWithOptions:launchOptions]; 

    /** 
    * Loading JavaScript code - uncomment the one you want. 
    * 
    * OPTION 1 
    * Load from development server. Start the server from the repository root: 
    * 
    * $ npm start 
    * 
    * To run on device, change `localhost` to the IP address of your computer 
    * (you can get this by typing `ifconfig` into the terminal and selecting the 
    * `inet` value under `en0:`) and make sure your computer and iOS device are 
    * on the same Wi-Fi network. 
    */ 

    jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"]; 

    /** 
    * OPTION 2 
    * Load from pre-bundled file on disk. The static bundle is automatically 
    * generated by the "Bundle React Native code and images" build step when 
    * running the project on an actual device or running the project on the 
    * simulator in the "Release" build configuration. 
    */ 

// jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; 

    RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation 
                 moduleName:@"MyAwesomeApp" 
               initialProperties:nil 
                launchOptions:launchOptions]; 

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

/** 
* Facebook SDK 
* 
**/ 

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

@end 

Avec ces configurations, je suis en mesure de se connecter avec mon serveur, les utilisateurs de connexion, etc.

Bonne chance!

+0

Super réponse! Courir et se connecter parfaitement maintenant. On dirait que j'ai fait une erreur dans le info.plist. Mais maintenant j'en ai un autre que vous pourriez connaître la réponse à si vous pouviez jeter un coup d'oeil: http://stackoverflow.com/questions/37061266/share-an-image-with-react-native-fbsdk. Merci. – nicholas