简体   繁体   中英

Swift 3 and Facebook swift SDK

I've been trying to understand how to integrate Facebook SDK for swift in an app I'm creating. I've used the cocoapods:

pod 'FacebookCore'

pod 'FacebookShare'

https://github.com/facebook/facebook-sdk-swift

I'm writing my app with swift 3 and I just want my Users to be able to post a message (Content) on their newsfeed with a hashtag and the app logo and also be able to share a picture taken within the app with the hashtag and a message(Content). (All without the Facebook login Framework)

I've read the documentation for Facebook SDK swift and also the documentation for Facebook IOS SDK:

https://developers.facebook.com/docs/swift

https://developers.facebook.com/docs/ios/getting-started

However, I'm not sure if I'm supposed to follow the first steps shown in the Facebook IOS documentation (adding to the info.plist and etc.) in order to have connectivity between Facebook and my app to be able to post. Thats because in the Facebook Swift documentation it doesn't say nothing about it. It just says to install the framework and thats it.

I was wondering if anyone knows what should I do? Does anyone know about a Video tutorial or a step by step tutorial? (Sharing Facebook Content)

(All the tutorials I've found are from the beginning of the year (outdated) and show the login setup only (Not On Swift). And also showing the old method of using Import Social, SLComposeViewController that doesn't work anymore and only works for twitter.)

Thanks..

PS. I've already Linked the frameworks and Libraries in my app. And also get the following warning:

ld: warning: directory not found for option '-F/Users/Siles/Desktop/PartyTime/build/Debug-iphoneos/FBSDKCoreKit'

ld: warning: directory not found for option '-F/Users/Siles/Desktop/PartyTime/build/Debug-iphoneos/FBSDKShareKit'

6 7 8 9 10 11 12 platform :ios, '9.0'

target 'FBSwiftLogin' do use_frameworks!

# Pods for FBSwiftLogin

pod 'FacebookCore'
pod 'FacebookLogin'
pod 'FacebookShare'

end

import FBSDKLoginKit

@UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
}

func applicationWillResignActive(_ application: UIApplication) {
    FBSDKAppEvents.activateApp()
}

func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
    return FBSDKApplicationDelegate.sharedInstance().application(application, open: url, sourceApplication: sourceApplication, annotation: annotation)
}

}

ViewController.swift

import UIKit import FBSDKLoginKit

class ViewController: UIViewController {

var dict : [String : AnyObject]!

override func viewDidLoad() {
    super.viewDidLoad()
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
}

@IBAction func btnFBLoginPressed(_ sender: AnyObject) {
    let fbLoginManager : FBSDKLoginManager = FBSDKLoginManager()
    fbLoginManager.logIn(withReadPermissions: ["email"], from: self) { (result, error) in
        if (error == nil){
            let fbloginresult : FBSDKLoginManagerLoginResult = result!
            if fbloginresult.grantedPermissions != nil {
                if(fbloginresult.grantedPermissions.contains("email"))
                {
                    self.getFBUserData()
                    fbLoginManager.logOut()
                }
            }
        }
    }
}

func getFBUserData(){
    if((FBSDKAccessToken.current()) != nil){
        FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, last_name, picture.type(large), email"]).start(completionHandler: { (connection, result, error) -> Void in
            if (error == nil){
                self.dict = result as! [String : AnyObject]
                print(result!)
                print(self.dict)
            }
        })
    }
}

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM