我無法同時使用下面的環境得到了Facebook登錄組件解決後雨燕的Facebook SDK空白頁iOS的10登錄
我已經遵循所有必要的步驟開始下載(iOS Getting Started和Swift Getting Started),即使在這裏沒有提到,如添加默認的AppDelegate方法如下步驟:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FacebookCore.SDKApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: [
.sourceApplication: application,
])
return true
}
private func application(app: UIApplication, openURL url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool {
return FacebookCore.SDKApplicationDelegate.shared.application(app, open: url, options: [
.sourceApplication: app,
])
}
@available(iOS 9.0, *)
private func application(application: UIApplication, openURL url: URL, sourceApplication: String?, annotation: AnyObject) -> Bool {
return FacebookCore.SDKApplicationDelegate.shared.application(application, open: url, sourceApplication: sourceApplication, annotation: annotation)
}
至於Info.plist中的內容,關於Facebook的一部分,我想我擁有所有必需的標籤,甚至有些人似乎有助於解決這種情況,在一些問題在這裏找到在SO:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>fb1619016601757957</string>
</array>
</dict>
</array>
<key>FacebookAppID</key>
<string>1619016601757957</string>
<key>FacebookDisplayName</key>
<string>Nossa Cidade</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fb-messenger-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>
</array>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>facebook.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<true/>
</dict>
<key>fbcdn.net</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<true/>
</dict>
<key>akamaihd.net</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<true/>
</dict>
</dict>
</dict>
對於最後和核心部分,超級簡化,我在登錄控制器中附加登錄按鈕邏輯。
override func viewDidLoad() {
super.viewDidLoad()
loginButton = LoginButton(readPermissions: [.publicProfile, .userFriends, .email])
loginButton.center = view.center
loginButton.frame.origin = CGPoint(x: loginButton.frame.origin.x,y: loginBtn.frame.origin.y + 80)
self.view.addSubview(loginButton)
loginButton.delegate = self
}
func loginButtonDidCompleteLogin(_ loginButton: LoginButton, result: LoginResult) {
switch result {
case .success(let grantedPermissions, _, let accessToken):
print("facebook success")
print(accessToken.authenticationToken)
break
case .cancelled:
print("facebook cancelled")
break
case .failed(let error):
print("facebook error")
break
}
}
func loginButtonDidLogOut(_ loginButton: LoginButton) {
print("User has logged out")
}
我已經經歷了很多的做題,Github上的問題了,並且有運行到同樣的情況我一些開發商,沒有關於此錯誤的可能結果有任何具體的迴應。到底發生了什麼,是我得到了一個胖胖的LoginResult.cancelled回調,而不是我想要的。
從控制檯輸出,與此相關的是:
-canOpenURL: failed for URL: "fbauth2:/" - error: "The operation couldn’t be completed. (OSStatus error -10814.)"
任何幫助,將不勝感激。謝謝!
原來appDelegate中的函數簽名是不匹配的。複製時請注意,我猜測參數名稱已被省略,即(__)並且未被調用。我知道它的通用性,但很久以前。無論如何謝謝你! –