0
votes

In my app i integrated facebook login , and put all the settings required. But when i was trying to login , i get this error

-canOpenURL: failed for URL: "fbauth2:/" - error: "(null)"

But i have put the

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

in the .plist file , is there anyway that i can find the issue ??

edited

 self.loginButton.delegate = self;
        if (FBSDKAccessToken.currentAccessToken() != nil)
        {
            // User is already logged in, do work such as go to next view controller.
        }
        else
        {

            loginButton.center = self.view.center
            loginButton.readPermissions = ["public_profile", "email", "user_friends"]
            loginButton.delegate = self
        }


    //MARK : facebook integration
    func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) {

        print(result);
        if ((error) != nil)
        {
            // Process error
            self.showCancelAlert("Error", message: "Error occured")
        }
        else if result.isCancelled {
            // Handle cancellations
        }
        else {
            // If you ask for multiple permissions at once, you
            // should check if specific permissions missing
            if result.grantedPermissions.contains("email")
            {
                // Do work
                self.returnUserData();

            }else{
                self.showCancelAlert("Error", message: "Cannot process with your email address")

            }
        }
    }

    func loginButtonDidLogOut(loginButton: FBSDKLoginButton!) {

    }

    // accessToken is your Facebook id
    func returnUserProfileImage(accessToken: NSString) -> String
    {
        let userID = accessToken as NSString
        let facebookProfileUrl = NSURL(string: "http://graph.facebook.com/\(userID)/picture?type=large")

        if facebookProfileUrl?.absoluteString != nil{
            return (facebookProfileUrl?.absoluteString)!;
        }else{
            return "";
        }

    }




    func returnUserData()
    {
        let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: nil)
        graphRequest.startWithCompletionHandler({ (connection, result, error) -> Void in

            if ((error) != nil)
            {
                // Process error
                 print("error \(error)")

            }
            else
            {
                let userName : NSString = result.valueForKey("name") as! NSString

                 UserDefaults.sharedInstace.setUsername(userName as String)

                if result.valueForKey("email") != nil{

                    let userEmail : NSString = result.valueForKey("email") as! NSString

                    if let id: NSString = result.valueForKey("id") as? NSString {
                        print("ID is: \(id)")

                        self.showLoading("Signin...")
                        WebClient.sharedInstace.socialLogin(SocialLogin(uid:String(id) , name: userName as String, imageUrl: self.returnUserProfileImage(id), email: userEmail as String, provider: "facebook"))

                    } else {
                        print("ID es null")

                        self.showCancelAlert("Error", message: "Cannot process with your email address")

                        self.loginButtonDidLogOut(self.loginButton)
                    }
                }else{

                    FBSDKLoginManager().logOut()

                    self.loginButtonDidLogOut(self.loginButton)

                    print("email es null")

                    self.showCancelAlert("Error", message: "Cannot process with your email address")

                }

            }
        })
    }
1
Can you post the code behind the login button?Ahmad Baracat
@AhmedBaracat i have updated the codeMr.G
Did you check this answer? stackoverflow.com/a/36290094/826926Ahmad Baracat
aparenty it was true. there wasnt any error in my implementation , if i test this with a real user , it worksMr.G

1 Answers

1
votes

I think there are a couple things that could cause your problem.

1) Are you sure that you have added the most recent FBSDKCoreKit and FBSDKLoginKit and added these lines to the top of your swift file:

import FBSDKCoreKit
import FBSDKLoginKit

2) I have read that this is just an error on the simulator and should be ignored. Make sure that you are testing on a real device for this feature.

3) Have you included the FBSDKLoginButtonDelegate in the heading of your class declaration?

4) I would make sure that your info.plist source code is all included and correct. Here is what I have added for Facebook in my app:

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>fbapi</string>
    <string>fb-messenger-api</string>
    <string>fbauth2</string>
    <string>fbshareextension</string>
</array>
<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string> fb + FACEBOOKAPPIDFROMTHEFACEBOOKDEVCONSOLE </string>
        </array>
    </dict>
</array>
<key>FacebookAppID</key>
<string>FACEBOOKAPPIDFROMTHEFACEBOOKDEVCONSOLE</string>
<key>FacebookDisplayName</key>
<string>NAME OF YOUR 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>
    </dict>
</dict>