How to integrate Facebook without redirect Safari browser in iOS app with latest FBSDK
yesterday I submit my app to store using FBSDKLoginManager
using three kinds of Login with Facebook , actually Facebook follow the first three conditions automatically
Type -1
if the user already installed the Facebook native app the details will be retrieved from the app.
Type -2
if the user does't have the Facebook app, but he is logged in at the device's Settings, the user details will be taken from those.
Type -3
if none of the condition above is satisfied the user will be automatically redirected to Safari
.
Type -4
if you none of the above three conditions is relevant for you please continue below code.
apple does not reject your app
Objective-C
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
login.loginBehavior=FBSDKLoginBehaviorWeb; // it open inside the app using popup menu
Swift
var fbLoginManager : FBSDKLoginManager = FBSDKLoginManager()
fbLoginManager.loginBehavior = FBSDKLoginBehavior.Native
FBSDKLoginBehavior Types
typedef NS_ENUM(NSUInteger, FBSDKLoginBehavior)
{
/*!
@abstract Attempts log in through the native Facebook app. If the Facebook app is
not installed on the device, falls back to \c FBSDKLoginBehaviorBrowser. This is the
default behavior.
*/
FBSDKLoginBehaviorNative = 0,
/*!
@abstract Attempts log in through the Safari browser
*/
FBSDKLoginBehaviorBrowser,
/*!
@abstract Attempts log in through the Facebook account currently signed in through Settings.
If no Facebook account is signed in, falls back to \c FBSDKLoginBehaviorNative.
*/
FBSDKLoginBehaviorSystemAccount,
/*!
@abstract Attemps log in through a modal \c UIWebView pop up
@note This behavior is only available to certain types of apps. Please check the Facebook
Platform Policy to verify your app meets the restrictions.
*/
FBSDKLoginBehaviorWeb,
};
the new concept
Facebook SDK for iOSv4.x
(v4.6.0 - September 10, 2015) In addition, the SDK dialogs such as Login, Like, Share Dialogs automatically determine the best UI based on the device, including SFSafariViewController instead of Safari. Follow the our Preparing for iOS 9 guide.
you can get like
Latest Facebook SDK opens safari get reject in app store?
if you added more than these permission you need to submit for Facebook in your app, then Facebook takes the 7 -10 working days for check. if everything is fine you can upload your app in App Store else your app has rejected.
and Facebook submission process
if it is not the error for your app please ref this link
Facebook login through application through Facebook SDK in iOS?
We can check we have a Facebook application or not. But if you redirect the user to Facebook app, then there will not any login page in the FB app. Because Facebook .native
for loginBehavior
uses Safari to open user login.
In that Safari browser, you will have one option to open in the app. The user can either click on that and authorise in-app itself or just go by writing credentials on safari.
Update:
We can check Whether the user has installed a Facebook app or not with URI Scheme. But before that you have to register like this in your info.plist:
Open info.plist as a Source Code like this:
And paste below code.
LSApplicationQueriesSchemes
fb
Now check like this:
BOOL isFBInstalled = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"fb://"]]
if (isFBInstalled) { //Check if FB app installed
//Do something
}
How to completely Logout of Facebook SDK Auth in iOS App
I was able solve my this issue by changing the FBSDKLoginBehavior
to web, see here: https://stackoverflow.com/a/44101753/1258525
New facebook login redirect flow on iOS
You can try changing the loginBehavior
of the login manager. See https://github.com/facebook/facebook-ios-sdk/blob/master/FBSDKLoginKit/FBSDKLoginKit/FBSDKLoginManager.h#L72. That alert is part of iOS 11' SFAuthenticationSession auth flow.
/**
This is the default behavior, and indicates logging in through the native
Facebook app may be used. The SDK may still use Safari instead.
*/
case native
/**
Attempts log in through the Safari or SFSafariViewController, if available.
*/
case browser
/**
Attempts log in through the Facebook account currently signed in through
the device Settings.
@note If the account is not available to the app (either not configured by user or
as determined by the SDK) this behavior falls back to \c .native.
*/
case systemAccount
/**
Attempts log in through a modal \c UIWebView pop up
@note This behavior is only available to certain types of apps. Please check the Facebook
Platform Policy to verify your app meets the restrictions.
*/
case web
How to Open Social App Login within application using URL Scheme
Yes you are right, You need to customize URL Scheme handling little bit.
Here is example code
Basically You need to add Principle UIApplication class in .pList file as bellow Image and add notification center when you get URL login for your app ID.
and than, (Application.m)
- (BOOL)openURL:(NSURL*)url {
if ([[url absoluteString] hasPrefix:@"https://m.facebook.com/v2.2/dialog/oauth?sdk_version="]) {
[[NSNotificationCenter defaultCenter] postNotificationName:ApplicationAuthNotificationFB object:url];
return NO;
}
return [super openURL:url];
}
and
Register Notification in your ViewController, (ViewController.m)
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(callLoginPopup:)
name:@"ApplicationAuthNotificationFB"
object:nil];
Method to handle URL (ViewController.m)
-(void)callLoginPopup:(NSNotification *)notif{
NSLog(@"URL To Handle ===> %@", [notif object]);
}
You can modify this example to achieve other social login within your app.
Facebook SDK login never calls back my application on iOS 9
Turns out that on iOS 9 when UIApplicationDelegate
's application:openURL:options:
is implemented, application:openURL:sourceApplication:annotation:
will not get called.
So what I had to do is call FBSDKApplicationDelegate
's application:openURL:sourceApplication:annotation:
from UIApplicationDelegate
's application:openURL:options:
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options {
return [[FBSDKApplicationDelegate sharedInstance] application:app
openURL:url
sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
annotation:options[UIApplicationOpenURLOptionsAnnotationKey]];
}
Related Topics
Change Language in the App Programmatically in iOS
Is It Considered a Private API to Use App-Prefs:Root
Property Not Working with Getter and Setter
How to Post String with Special Character and Thai Language Using Xml Parsing in Objective C
How to Test If a String Is Empty in Objective-C
How to Disable Back Swipe Gesture in Uinavigationcontroller on iOS 7
How to Create a Uiview Bounce Animation
Dynamically Changing Font Size of Uilabel
How to Play a Sound Using Swift
How to Initialize/Instantiate a Custom Uiview Class with a Xib File in Swift
Detecting Collisions in Sprite Kit
How to Achieve a "Clock Wipe"/ Radial Wipe Effect in iOS
Combine Framework: How to Process Each Element of Array Asynchronously Before Proceeding
Cannot Change Search Bar Background Color
How to Find File Uti for File, Withouth Pathextension, in a Path in Swift
Arkit - Apply Cifilter to a Specific Vertices of Arfaceanchor
How to Determine Which Apps Are Background and Which App Is Foreground on iOS by Application Id