Facebook apps using react native. Can't find ViewController.m - ios

I'm creating an app using react native and xcode. I've been following the set up instructions on facebook because I'm going to implement their login. However it says to add some code into ViewController.m in your xcode project, but when I initialize a new react project in terminal, it doesn't create one. I also can't find the ViewDidLoad method. Any suggestions?
In one of your app's ViewController.m files, and also in the AppDelegate.m file add:
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>
In the ViewController.m file, add the following code to the viewDidLoad method:
FBSDKLoginButton *loginButton = [[FBSDKLoginButton alloc] init];
loginButton.center = self.view.center;
[self.view addSubview:loginButton];
Add this method in your app's AppDelegate.m file:
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation];
}

Solved. React Native doesn't create ViewController files. If you are using React Native and the facebook app guide, disregard the 'Let's test out your integration' steps.

Related

No known class method (facebook sdk integration)

I'm trying to add the react-native-fbsdk-next into my react-native app. The documentation says to add the following lines to the AppDelegate.m file to enable AEM (Aggregated Event Measurement)
#import <FBAEMKit/FBAEMKit.h>
[FBAEMReporter configureWithNetworker:nil appID:{app-id}];
[FBAEMReporter enable];
[FBAEMReporter handleURL:url]
After I added these lines of code like this:
(BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
[FBAEMReporter configureWithNetworker:nil appID:123456789]; // in the code I use the real app Id
[FBAEMReporter enable];
[FBAEMReporter handleURL:url];
#if defined(EX_DEV_LAUNCHER_ENABLED)
if ([EXDevLauncherController.sharedInstance onDeepLink:url options:options]) {
return true;
}
#endif
return [super application:application openURL:url options:options] || [RCTLinkingManager application:application openURL:url options:options];
}
the build fails with the following error no known class method for selector 'configureWithNetworker:appID:'. I can't find or understand how to fix this issue, the documentation doesn't provide any additional information/steps to follow. Any advise or help is greatly appreciated.
It looks like a mistake in the react-native-fbsdk-next README
the underlying method signature in the native Facebook iOS SDK is:
+ (void)configureWithNetworker:(nullable id<FBAEMNetworking>)networker
appID:(nullable NSString *)appID
reporter:(nullable id<FBSKAdNetworkReporting>)reporter;
So the call should be:
[FBAEMReporter configureWithNetworker:nil appID:#"1234556" reporter:nil];
[FBAEMReporter enable];
[FBAEMReporter handleURL:url];
(note that appID is a string, also I am unfamiliar with the SKAdNetworkReporter but it is nullable so it builds passing in nil).

React native fbsdk login IOS white screen

i am having problem using official react-native-fbsdk package for facebook login, it works well in android but in IOS after the login finished or cancelling it redirects to blank page instead of going back to my app.
What I have done :
Linked react-native-fbsdk
Followed IOS getting started guide in facebook page
any help will be appreciated.
You need to modify your AppDelegate.m file in ios project
Facebook react-native faq
This problem indicates that the code in the AppDelegate.m file hasn't been setup properly. Confirm that your code is similar to this example:
AppDelegate.m
#import <FBSDKCoreKit/FBSDKCoreKit.h>
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
// Add any custom logic here.
return YES;
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
BOOL handled = [[FBSDKApplicationDelegate sharedInstance]
application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation
];
// Add any custom logic here.
return handled;
}

"You have already authorized yourApp" when logging in using FBSDK 4.7.1

I was following Facebook's own tutorial for FB login in iOS (Objective-C) but every time I log in - after the initial permission authorization screen - I'm getting the infamous "You have already authorized this app" webview.
I've read a ton of posts but I haven't been able to sort it out, hence the (re)post. I find this rather odd because the app has absolutely nothing except the boilerplate login code. This behaviour happens in both Simulator and real devices.
This app is for iOS 9.0 and I am using FBSDK 4.7.1 (installed via CocoaPods):
pod 'FBSDKLoginKit', '~> 4.6'
The code itself is pretty boilerplate stuff, here's my AppDelegate.m:
#import "AppDelegate.h"
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#interface AppDelegate ()
#end
#implementation AppDelegate
- (void)applicationDidBecomeActive:(UIApplication *)application {
[FBSDKAppEvents activateApp];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
return YES;
}
- (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
and my ViewController.m:
#import "ViewController.h"
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
FBSDKLoginButton *loginButton = [[FBSDKLoginButton alloc] init];
loginButton.readPermissions = #[#"public_profile", #"email", #"user_friends"];
[loginButton setLoginBehavior:FBSDKLoginBehaviorSystemAccount]; // No difference
loginButton.center = self.view.center;
[self.view addSubview:loginButton];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
And a screenshot of the Info.plist:
Finally, I'm also getting these two errors in the console:
2015-11-24 11:50:42.855 lixo[26941:389756] -canOpenURL: failed for URL: "fbauth2:/" - error: "(null)"
2015-11-24 11:50:42.860 lixo[26941:389756] -canOpenURL: failed for URL: "fbauth2:/" - error: "(null)"
Although from what I've read this can be safely ignored if LSApplicationQueriesSchemes is set in the Info.plist.
Any ideas how to avoid this?
Instead of triggering a login on every launch, you can check the status of the access token. If it's not expired, you skip login, and just start using the API. The following method can be used to check if the token is expired:
+(BOOL) accessTokenIsLocalyValid
{
return [FBSDKAccessToken currentAccessToken] && [[NSDate date] compare:[FBSDKAccessToken currentAccessToken].expirationDate] == NSOrderedAscending;
}
If you have a valid token, you can refresh it using [FBSDKAccessToken refreshCurrentAccessToken:].
Check if there is a current session before logging in with FBSDKLoginManager.
if ([FBSDKAccessToken currentAccessToken])
{
NSLog(#"Token is available : %#",[[FBSDKAccessToken currentAccessToken]tokenString]);
// Now get details using graphpath.
} else {
// login with permissions using FBSDKLoginManager and get details using graphpath in completion
}
This is the default behaviour!
Facebook SDK allows you to login to facebook from Facebook App (if it is installed in your phone), OR else it will manage the login from Safari.
And when Facebook login is used by your application from Safari, this is how you have to accept permission everytime.
Another behaviour is that If your iphone doesnt have Facebook App, and you use Facebook SDK login process from your application, it will use Safari; you wont be able to logout even, as Safari saves your credentials in cookies and there is no way by which you can clear safari cookies from your application.
If your phone has Facebook App, it will redirect to your application without any interruptions as such.
EDIT -
This behaviour is also found in iOS 10.
Thanks for the edit - Tiois

ios Facebook Login button - doesn't change to Log out

I'm using Xcode 6 & Facebook iOS SDK 4.3,
I embedded the code, according to Facebook's guide and the login works, BUT
from some reason -
after I login, the button doesn't change to "Log out", and stays "Log in with Facebook".
did anyone encounter this problem?
so I started all over, and followed the instructions from the guide:
1.in the viewController.h file:
#import < FBSDKCoreKit/FBSDKCoreKit.h> //<-delete the space
#import < FBSDKLoginKit/FBSDKLoginKit.h>//<-delete the space
#interface ViewController : UIViewController<FBSDKLoginButtonDelegate>
#property (weak, nonatomic) IBOutlet FBSDKLoginButton *loginButton;
2.in the viewController.m file:
-(void) viewDidLoad{
if ([FBSDKAccessToken currentAccessToken]) {
// User is logged in, do work such as go to next view controller.
}
self.loginButton.readPermissions = #[#"public_profile", #"email", #"user_friends"];
FBSDKLoginButton *loginButton = [[FBSDKLoginButton alloc] init];
[self.view addSubview:loginButton];
}
and after that didn't work, I've found this thread that mentioned I also need to add few things to the AppDelegate didFinishLaunchingWithOptions :
return [[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
and
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
and then it worked!
finally I had the Log in button changed to Log out!
I was experiencing the same issue, and couldn't find the answer anywhere.
Turns out it was a Simulator problem; once I ran the same code on the device (iOS 9.3.1) everything worked out fine.
Remember to enable keychain sharing capability

Facebook delegates are not calling after authentication: cocos2d

He guys, I am doing a photo share in my cocos2d application with Facebook SDK. I've a problem that: the login view with status Not Logged In is remaining even after authentication. I'm attaching the images:
Problem: After clicking the Skip or OK button of the Authentication page, the status has to be changed as Login. But it isn't. No Facebook delegates are getting called after Auth(When I enter the page first time, loginViewShowingLoggedOutUser delegate was get called. After auth, nothing is get called.).
What I've done already:
Downloaded the Facebook SDK, attached to the project.
Added FacebookAppID,FacebookDisplayName and URL Schemes in info.plist.
Tried the integration with my cocos2d app.
Added <FBLoginViewDelegate> in .h.
Added loginview.delegate = self in .m.
I'm also uploading the screenshot of what I've done in my info.plist:
I am creating the login view as:
// Create Login View so that the app will be granted "status_update" permission.
FBLoginView *loginview = [[FBLoginView alloc] init];
loginview.frame = CGRectOffset(loginview.frame, 5, 5);
#ifdef __IPHONE_7_0
#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_7_0
if ([self respondsToSelector:#selector(setEdgesForExtendedLayout:)]) {
loginview.frame = CGRectOffset(loginview.frame, 5, 25);
}
#endif
#endif
#endif
loginview.delegate = self;
[[[CCDirector sharedDirector]view]addSubview:loginview];
[loginview sizeToFit];
What I found:
The following method in appdelegate is not get called:
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
// attempt to extract a token from the url
return [FBAppCall handleOpenURL:url
sourceApplication:sourceApplication
fallbackHandler:^(FBAppCall *call) {
NSLog(#"In fallback handler");
}];
}
Further info:
Xcode Version 5.0.1
iOS Version 7.0
facebook-ios-sdk-3.9
Any help ASAP is appreciable.
Thanks.
Sorry guys.... #elio.d: and thank you very much for your valuable suggestion . That was my mistake with coding. I have pasted the following method, just above #implementation AppController. What an idiot I am. This just wasted one of my whole day... :
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
}
This just saved me. Hope this might be helpful for some others like me. :)
You have to add an url scheme in your app to make the facebook app / website call your app back after login or authorization link to the documentation, this is the reason why your app is not called

Resources