0

I'm trying to integrate a facebook login, well:

I downloaded the FacebookSDKs-iOS-4.18.0 2 from the developer facebook site.

After that, I added the next xml in my info.plist file:

<key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>fb21200000000000</string>
            </array>
        </dict>
    </array>
    <key>FacebookAppID</key>
    <string>21200000000000</string>
    <key>FacebookDisplayName</key>
    <string>San Miguel Digital</string>
    <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>fbapi</string>
        <string>fb-messenger-api</string>
        <string>fbauth2</string>
        <string>fbshareextension</string>
    </array>
    <key>NSPhotoLibraryUsageDescription</key>
    <string>{human-readable reason for photo access}</string>

AppDelegate.swift

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
    }

LoginViewController.swift

import Foundation
import UIKit
//import FacebookCore
//import FacebookLogin
import FBSDKCoreKit
import FBSDKLoginKit

class LoginViewController: UIViewController, FBSDKLoginButtonDelegate {

    override func viewDidLoad(){
        super.viewDidLoad()
        /*let loginButton = LoginButton(readPermissions: [ .publicProfile, .email ])
        loginButton.center = view.center

        view.addSubview(loginButton)*/

        if(FBSDKAccessToken.current() == nil){
            print("Is not logged in")
        }else{
            print("Currently is logged in")
        }

        let loginButton = FBSDKLoginButton()
        loginButton.readPermissions = ["public_profile", "email"]
        loginButton.center = self.view.center

        loginButton.delegate = self
        self.view.addSubview(loginButton)
    }

    func loginButtonDidLogOut(_ loginButton: FBSDKLoginButton!) {
        print("Logged out")
    }

    func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!) {
        if(error == nil){
            print("Successfully logged")
        }else{
            print(error.localizedDescription)
        }
    }



}

The facebook login button appears when I execute the application on the iphone device, but in the log error, I get:

Is not logged in libc++abi.dylib: terminating with uncaught exception of type NSException warning: could not load any Objective-C class information. This will significantly reduce the quality of type information available.

What I'm doing wrong?

Benjamin RD
  • 11,516
  • 14
  • 87
  • 157
  • `terminating with uncaught exception of type NSException` there is always more to the error than just this message. Post the full exception log and backtrace. – JAL Jan 26 '17 at 18:04
  • could you try with Product->Clean – Nazmul Hasan Jan 26 '17 at 18:06
  • First, post full error message. Second, I achieved this functionality last month. I am pretty sure there are at lease 3 functions should be added to AppDelegate. But it seems that you only add one (or post one here?) – Eric Zhang Jan 26 '17 at 19:55
  • @EricZhang that is all the error, I tried to display more, but the xcode is not displaying any more. Can you paste the other methods that you're using? Maybe I'm forgiving something – Benjamin RD Jan 26 '17 at 20:11

1 Answers1

0

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"])
                }
            }
        }
    }
}
Eric Zhang
  • 164
  • 11