Facebook Sdk Login Throws Error in Swift 2 iOS 9

Facebook SDK login throws error in swift 2 iOS 9

I have solved the problem. As there is no anything about LSApplicationQueriesSchemes in the documentation but I got an error message about the lack of it I wrote the key and the "fbauth2" value into the info.plist as a String but it is an array and the SDK try to get the element of the String Array without any check if it is an array.

However, thank you for the helping answers.

iOS 9 Facebook login simulator -canOpenURL: failed for URL: fbauth2:/// - error: (null)

Why do I see console messages like 'canOpenURL: failed for URL: "fb...://' or ?

This is an Xcode warning indicating the the canOpenURL: call returned
false. As long as you have configured the LSApplicationQueriesSchemes
entry in your plist as described above, you can ignore this warning.

Open this page in null' Modal appearing from FacebookSDK login after iOS9 and Swift 2 upgrade

Make sure that you have updated to the newest version of the Facebook SDK at http://fb.me/FacebookSDKs-iOS-20150910.zip.

You will also want to Whitelist the Facebook Servers for Network Requests.
More information on this can be found here.

Specifically look at steps #2 & #3.

From the documentation in Step #3 there were also changes to the canOpenURL method:

Why do I see console messages like 'canOpenURL: failed for URL: "fb...://' or ?
This is an Xcode warning indicating the the canOpenURL: call returned false. As long as you have configured the LSApplicationQueriesSchemes entry in your plist as described above, you can ignore this warning

Swift Facebook login is broken in dispatch_once

There are two functions you probably missed. You can find the detail by Google "iOS Facebook login" then choose first link. What I did was completely followed the instruction.

    func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
FBSDKAppEvents.activateApp()
}

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {

return FBSDKApplicationDelegate.sharedInstance().application(app, open: url, options: options)
}

And I check your implementation in func loginButton. there is a sample that might be better practice:

func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!) {
guard error == nil else {
print("Login Error: \(error)" )
return
}

if let token = FBSDKAccessToken.current() {
if let req = FBSDKGraphRequest(graphPath: "me", parameters: ["fields":"name"], tokenString: token.tokenString, version: nil, httpMethod: "GET") {
req.start() {
(conn, result, err) in
if ((err) != nil) {
print("Error: \(err)")
}
else {
let data:[String:AnyObject] = result as! [String : AnyObject]
print("username: " + data["name"])
}
}
}
}
}

IOS Facebook SDK: login doesn't return email despite permissions granted

Facebook Graph API broke it’s backward compatibility (when used in a default fashion) Since Graph-API version 2.4 (Pod Version 4.4.0).

FB Graph-API 2.4 does NOT return all default fields for user

To resolve this you can either use explicitly graph version 2.3:

[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil tokenString:[FBSDKAccessToken currentAccessToken].tokenString version:@"v2.3" HTTPMethod:nil]

in which case FB assures v2.3 will be available at least 2 years from now.
https://developers.facebook.com/docs/graph-api/overview:

The Graph API has multiple versions available to access at any one
time. Each version contains a set ofcore fields and edge operations.
We make a guarantee that those core APIs will be available and
un-modified in that version for at least 2 years from release. The
platform changelog can tell you which versions are currently
available.

OR

you can use new Graph-API (v2.4) in by asking for specific fields you are interested in:

[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields" : @"email,name"}]

Why am I getting com.facebook.sdk.login error 308?

For Xcode8 - iOS10,

Enable Keychain Sharing within Capabilities tab of target fixed my issue.

Sample Image

More details can be found here : https://github.com/facebook/facebook-sdk-swift/issues/51


For Xamarin Studio (Suggested by @Kenneth),

Add the Entitlements.plist file to Custom Entitlements under the iOS Bundle Signing options in the iOS project.

Facebook iOS SDK Something went wrong at login possible diagnostic

Here's what I came up with as a workaround, though fair warning it isn't a proper solution. I don't really like it as it's very hacky, but it works for now.

Before showing a the stream dialog, I check to see if the user is logged in. If not, I show the login dialog and then trigger the stream dialog in the DidLogin callback.
Basically I'm avoiding the automatic Login to Post Dialog transition.

swift 2 parse facebookSDK ios9

I suggest following the instructions from Facebook to prepare an app for iOS 9:
https://developers.facebook.com/docs/ios/ios9

  1. Download the latest Facebook SDK for iOS

Download the appropriate version of the Facebook SDK for your app.

v4.x - Recommended.
v3.24.0 - Only if you have not migrated to v4.x of the SDK yet.
2. Whitelist Facebook Servers for Network Requests

If you compile your app with iOS SDK 9.0, you will be affected by App Transport Security. Currently, you will need to whitelist Facebook domains in your app by adding the following to your application's plist:

<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>facebook.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
<key>fbcdn.net</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
<key>akamaihd.net</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
</dict>
</dict>

or you will encounter errors like:

NSUnderlyingError=0x7f88f9436eb0 {Error Domain=kCFErrorDomainCFNetwork
Code=-1200 "An SSL error has occurred and a secure connection to
the server cannot be made." UserInfo={NSErrorFailingURLStringKey=
https://graph.facebook.com/v2.4, NSLocalizedRecoverySuggestion=
Would you like to connect to the server anyway?,
_kCFNetworkCFStreamSSLErrorOriginalValue=-9802,
kCFStreamPropertySSLPeerCertificates=<CFArray 0x7f88f9536e00
[0x10719f7c0]>{type = immutable, count = 2, values = (
0 : <cert(0x7f88f963f840) s: *.facebook.com (http://facebook.com/)
i: DigiCert High Assurance CA-3>
1 : <cert(0x7f88f96444c0) s: DigiCert High Assurance CA-3 i:
DigiCert High Assurance EV Root CA> )},
_kCFStreamPropertySSLClientCertificateState=0,
kCFStreamPropertySSLPeerTrust=<SecTrustRef: 0x7f88f9644d10>,
NSLocalizedDescription=An SSL error has occurred and a secure connection
to the server cannot be made.,_kCFStreamErrorDomainKey=3,
NSErrorFailingURLKey=https://graph.facebook.com/v2.4,
_kCFStreamErrorCodeKey=-9802}}

  1. Whitelist Facebook Apps

If you use any of the Facebook dialogs (e.g., Login, Share, App Invites, etc.) that can perform an app switch to Facebook apps, you will need to update your application's plist to handle the changes to canOpenURL described in https://developer.apple.com/videos/wwdc/2015/?id=703

If you're recompiling with iOS SDK 9.0, add the following to your application's plist if you're using a version of the SDK v4.5 or older:

<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>

If you're using FBSDKMessengerShareKit from versions older than the v4.6 release, also add

<string>fb-messenger-platform-20150128</string>
<string>fb-messenger-platform-20150218</string>
<string>fb-messenger-platform-20150305</string>

If you're using v4.6.0 of the SDK, you only need to add:

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

This will allow the FacebookSDK integration to properly identify installed Facebook apps to perform an app switch. If you are not recompiling with iOS SDK 9.0, your app is limited to 50 distinct schemes (calls to canOpenURL afterwards return NO).



Related Topics



Leave a reply



Submit