facebook and google login open in application by sfsafariviewcontroller - ios

In my app user can login with facebook and google account. but when user click on facebook login or google login he will redirect to safari browser. So apple reject my app with below reason.
We noticed that the user is taken to Safari to sign in or register for an account, which provides a poor user experience. Next Steps To resolve this issue, please revise your app to enable users to sign in or register for an account in the app.
For resolving the issue I added facebook login behavior as the web "FBSDKLoginBehaviorWeb". Now when I open it, it is opening in the app only. but when I click on "Not Now" button on here is the facebook screen shot facebook it is crashing my app in the second time. Can anyone have answer to this issue? Also, can any one suggest me how do I solve the google sign on the issue too?

Try this :
Swift 4.0 snippet:
let loginManager = FBSDKLoginManager()
loginManager.logIn(withReadPermissions: ["email","public_profile"], from: self) { (result, error) in
if ((error) != nil) {
// Process error
} else if (result?.isCancelled)! {
// Handle cancellations
} else {
// If you ask for multiple permissions at once, you
// should check if specific permissions missing
if (FBSDKAccessToken.current() != nil)
{
FBSDKGraphRequest(graphPath: "me", parameters: ["fields":"email, name"]) .start(completionHandler: { (connectioon, result, error) in
if error == nil
{
print(result);
}
})
}
}
}
Make sure you have added these below items in info.plist:
1.
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fb-messenger-share-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>
</array>
2.
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>fbxxxxxxxxxxxxxx</string>
</array>
</dict>
</array>
<key>FacebookAppID</key>
<string>xxxxxxxxxxxx</string>
<key>FacebookDisplayName</key>
<string>App name</string>
Note: iOS should be greater than iOS 9.0 or later to use SFSafariViewController.

Try to handle is cancelled , also i use facebook sdk version 4.17.0
and click not know and works perfectly
facebookLogin.logIn(withReadPermissions: ["public_profile","email", "user_friends"], from:self, handler:
{
(facebookResult, facebookError) -> Void in
if facebookError != nil
{
print("Facebook login failed. Error \(String(describing: facebookError))")
}
else if (facebookResult?.isCancelled)!
{
print("Facebook login was cancelled.")
}
else
{
// success
}
});
see in action

Related

Facebook iOS SDK login error (Invalid Scopes: public_profile, openid.)

I receive the follow error when trying to login using the iOS Facebook SDK:
Invalid Scopes: public_profile, openid.
I have followed the instructions from here which has resulted in this set up:
info.plist
<plist version="1.0">
<dict>
...
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string></string>
<key>CFBundleURLSchemes</key>
<array>
<string>GOOGLE_URL_SCHEME</string>
<string>fbMY_FB_APP_ID</string>
</array>
</dict>
</array>
<key>FacebookAppID</key>
<string>MY_FB_APP_ID</string>
<key>FacebookClientToken</key>
<string>MY_FB_CLIENT_TOEN</string>
<key>FacebookDisplayName</key>
<string>MY_FB_APP_NAME</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbauth2</string>
<string>fbapi</string>
<string>fb-messenger-share-api</string>
</array>
</dict>
</plist>
AppDelegate.swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
ApplicationDelegate.shared.application( application, didFinishLaunchingWithOptions: launchOptions )
return true
}
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]
) -> Bool {
return ApplicationDelegate.shared.application(app, open: url, sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String, annotation: options[UIApplication.OpenURLOptionsKey.annotation])
}
Login snippet
let loginManager = LoginManager()
loginManager.logIn(permissions: ["public_profile"], from: self) { result, error in
if let error = error {
print("FB Error: \(error)")
} else if let result = result, result.isCancelled {
print("FB Cancelled")
} else {
print("FB Logged In")
}
}
I am on iOS 16.2 using the facebook-ios-sdk version 15.1.0. The same error occurs with FB app in live and development mode. I receive the same error on the simulator and device. I can successfully login on the web when using the FB app JS library. I believe I have followed the instructions correctly. What am I missing?
Edit: Settings Screenshots
Edit:
So I just downloaded this sample from the facebook-ios-sdk. Added my FB App Id to the FacebookAppID field and URL Schemes in the plist. Added the FB Client Token to the plist and updated the bundle identifier to the one listed in the Facebook app, but I get the same error when I run the sample. What the hell is going on? The issue must be in the Facebook app set up, but where? I can't find this issue reported anywhere on the net. Surely someone has seen this before.
I figured it out. I was missing the facebook login from my facebook app products. I found it by accident and now I can login successfully.

Twitter URL Schemes set up in info.plist are throwing an exception

Someone pointed out that this was a duplicate question, Yes partly, I followed the advice in the other post and added the URLScheme as shown below, Also as suggested i forgot to add to my other target so i did and the URL twitter-13145245245624 Now what happens is my app redirects the user to their Twitter App and asks for permission to have my app use their info, once tapping the ok button user is redirected back to my app but still no Composer populates the View to Tweet. Still confused. Thanks for all the help.
let composer = TWTRComposer()
composer.setText("just setting up my Twitter Kit")
composer.setImage(UIImage(named: "twitterkit"))
// Called from a UIViewController
composer.show(from: self) { (result) in
if (result == .done) {
print("Successfully composed Tweet")
} else {
print("Cancelled composing")
}
}
This is my info.plist, however, I have no issue with posting to Facebook.
Any thoughts?
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>twitterkit-xxxxxxxxxx</string>
<string>fbxxxxxx</string>
</array>
</dict>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>twitter</string>
<string>twitterauth</string>
</array>
Regards
J
The issue to my above question was that I did not have the below method in AppDelegate as so. This Solved my problem.
-(BOOL)application:(UIApplication*)app openURL:(nonnull NSURL *)url options:(nonnull NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options{
return [[TWTRTwitter sharedInstance]application:app openURL:url options:options];
}

Fast App Switch iOS 11 Facebook Login

Currently my facebook login does the following:
Tap the login with fb button
Asks for permission to to use "facebook.com" to log in
Asks whether to use app or log in with an email or phone in a Safari View Controller
If selected app: Asks to open Facebook app
Asks for permission to let the fb app use your to log in
Returns to app
Those are too many steps for me. I'd like to do something like Uber app, it's facebook login flow is:
Tap the login with fb button
Asks to open Facebook app
Asks for permission to let the fb app use your account to log in
Returns to app
Uber's flow:
Facebook Fast App Switch
There's an article that says theres a Fast App Switch way to login which is what I want for my app, If facebook app is installed I want the login to be done directly to the app.
I've used this code at my sign in button action with no luck:
let fbLoginManager = FBSDKLoginManager()
fbLoginManager.loginBehavior = .native
fbLoginManager.logIn(withReadPermissions: ["public_profile", "email"], from: self) { (result, error) in
let credential = FacebookAuthProvider.credential(withAccessToken: accessToken.tokenString)
// Perform login by calling Firebase APIs..
}
At my Info.plist:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>fbXXXXXXXX</string>
</array>
</dict>
</array>
<key>FacebookAppID</key>
<string>XXXXXXXX</string>
<key>FacebookDisplayName</key>
<string>My Beautiful App</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fb-messenger-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>
</array>
At my AppDelegate.swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions:launchOptions)
return true
}
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
let handled = FBSDKApplicationDelegate.sharedInstance().application(app, open: url, options: options)
return handled
}
Facebook SDK version: 4.27.1
Using FBSDKCoreKit (4.27.1)
FBSDKLoginKit (4.27.1)
FBSDKShareKit (4.27.1)

How to link iOS app to facebook page in Swift?

I'm trying to link my app to facebook page , I have used this code :
let facebookURL = NSURL(string: "fb://profile/turathalanbiaa")!
if UIApplication.sharedApplication().canOpenURL(facebookURL)
{
UIApplication.sharedApplication().openURL(facebookURL)
}
else
{
UIApplication.sharedApplication().openURL(NSURL(string: "https://www.facebook.com/turathalanbiaa")!)
}
info.plist
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fb</string>
</array>
but facebook app shows the user profile page not the page that I provided. what did I miss ?

Facebook login with Parse in iOS9 and Swift2

I am trying to login with Facebook with Parse in iOS9 but the application keep opening Safari instead of Facebook app in real device. and even in Safari when I try to use the keyboard to enter the email and password of Facebook account the page reload so it's impossible to login and give the permission to the app. The user should open safari and login first in Facebook then open my app and then give permission. I think it's not the best user experience since the user have already a Facebook app.
I have followed all the steps I will list them here:
Add Fraleworks
Link Binaries
Updaded info.plist
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>fb907580375984874</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key>
<string>1</string>
<key>FacebookAppID</key>
<string>907580375984874</string>
<key>FacebookDisplayName</key>
<string>Appname</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fbapi20130214</string>
<string>fbapi20130410</string>
<string>fbapi20130702</string>
<string>fbapi20131010</string>
<string>fbapi20131219</string>
<string>fbapi20140410</string>
<string>fbapi20140116</string>
<string>fbapi20150313</string>
<string>fbapi20150629</string>
<string>fbauth</string>
<string>fbauth2</string>
<string>fb-messenger-api20140430</string>
</array>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>akamaihd.net</key>
<dict>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
<key>facebook.com</key>
<dict>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
<key>fbcdn.net</key>
<dict>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>
</dict>
App Delegate
import UIKit
import Parse
import FBSDKCoreKit
import ParseFacebookUtilsV4
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
Parse.setApplicationId("appID", clientKey: "MyKey")
PFFacebookUtils.initializeFacebookWithApplicationLaunchOptions(launchOptions)
return true
}
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application,openURL: url,sourceApplication: sourceApplication, annotation: annotation)
}
func applicationDidBecomeActive(application: UIApplication) {
FBSDKAppEvents.activateApp()
}
}
Login code:
#IBAction func loginButtonClicked(sender: AnyObject) {
if let _ = FBSDKAccessToken.currentAccessToken() {
print("connected already")
} else {
PFFacebookUtils.logInInBackgroundWithReadPermissions(["public_profile", "email", "user_friends", "user_birthday" , "user_education_history","user_photos"]) {
(user: PFUser?, error: NSError?) -> Void in
if let user = user {
if user.isNew {
print("User signed up and logged in through Facebook!")
} else {
print("User logged in through Facebook!")
}
} else {
print("Uh oh. The user cancelled the Facebook login.")
}
}
}
}
Using a webview to log users in is now the default behaviour of the Facebook SDK for iOS 9 and according to Facebook team, this approach gives a better user experience as it avoids the additional dialogues being shown between app transitions.
In apps that use the newest SDK (v4.6 and v3.24), we will surface a
flow using Safari View Controller (SVC) instead of fast-app-switching
(FAS) because of additional dialog interstitials that add extra steps
to the login process in FAS on iOS 9. Additionally, data that we've
seen from more than 250 apps indicate that this is the best experience
for people in the long run
Read more on Facebook

Resources