試圖讓Facebook連接工作從一個迅速的項目。swift 3 facebook整合
一直試圖沿着以下YouTube視頻如下:https://www.youtube.com/watch?v=I6rTmfLp9aY
不幸,我是在德國。
所以這是我到目前爲止有:
我有我的IOS的Facebook應用程序啓用啓用和我種我的bundleID那裏。
下載最新的iOS框架,並添加到項目
到AppDelegate的文件,我說:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
FBSDKApplicationDelegate.sharedInstance()
return true
}
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()
}
這就是視圖控制器文件
import UIKit
import FBSDKCoreKit
import FBSDKLoginKit
import FBSDKShareKit
class ViewController: UIViewController, FBSDKAppInviteDialogDelegate, FBSDKLoginButtonDelegate{
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
if (FBSDKAccessToken.current() != nil)
{
let content = FBSDKAppInviteContent()
content.appLinkURL = NSURL(string: "{Facebook link to app}") as URL!
FBSDKAppInviteDialog.show(from: self, with: content, delegate: self)
}
else
{
let loginView : FBSDKLoginButton = FBSDKLoginButton()
self.view.addSubview(loginView)
loginView.center = CGPoint(x: self.view.frame.midX, y: self.view.frame.midY + 100)
loginView.readPermissions = ["public_profile", "email"]
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func appInviteDialog (_ appInviteDialog: FBSDKAppInviteDialog!, didCompleteWithResults results: [AnyHashable : Any]!)
{
}
func appInviteDialog (_ appInviteDialog: FBSDKAppInviteDialog!, didFailWithError error: Error!) {
print("Error took place in appInviteDialog \(error)")
}
func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!) {
if ((error) != nil)
{
//process error
}
else if result.isCancelled {
//handle cancelation
}
else {
let content = FBSDKAppInviteContent()
content.appLinkURL = NSURL(string: "{Facebook link to app}") as URL!
FBSDKAppInviteDialog.show(from: self, with: content, delegate: self)
if result.grantedPermissions.contains("email")
{
//do work
}
}
}
func loginButtonDidLogOut(_ loginButton: FBSDKLoginButton!) {
}
}
沒有錯誤,沒有警報。當我運行模擬器時,我得到一個空的屏幕。必須做一些正確的事情,因爲我得到了以下信息:
SystemGroup/systemgroup.com.apple.configurationprofiles 2017年6月4日00:42:02.351876 + 0300 facebook_login [4569:144075] [MC]從私人閱讀有效的用戶設置。
也是,如果我只是在viewDidLoad中粘貼在以下幾行代碼:
let loginView : FBSDKLoginButton = FBSDKLoginButton()
self.view.addSubview(loginView)
loginView.center = CGPoint(x: self.view.frame.midX, y: self.view.frame.midY + 100)
loginView.readPermissions = ["public_profile", "email"]
我在模擬器得到一個漂亮的Facebook按鈕當然死機當我按下它。
任何幫助的工作將是極大的讚賞
我知道Facebook的swift sdk不支持當前的swift和Xcode –
我正在使用Xcode和Swift的最新版本,僅僅是建立框架的一些小警告。無論如何,他們沒有那麼不同,我敢肯定,如果你更喜歡其他SDK,你可以用它們完成同樣的事情。只要確保遵循文檔中的所有步驟。注意App Delegate和Info.plist。代碼現在可以使用 –
。我忘記了更新Info.plist。謝謝 –