我单击Facebook按钮,但是在iOS 13上没有响应,但是在iOS 12.x上它可以正常工作。我该怎么办?
我正在使用:1)pod'FBSDKCoreKit','〜> 5.13.1'2)pod'FBSDKLoginKit','〜> 5.13.1'3)pod'FacebookCore'4)pod'FacebookLogin'5)pod'FacebookShare'
您的开放式url方法中的appdelegate无法使用,因为ios13发生了更改
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any]) -> Bool {
return
}
您必须比添加此方法的SceneDelegate.swift文件更新最新的xcode。请尝试。
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
guard let url = URLContexts.first?.url else {
return
}
let _ = ApplicationDelegate.shared.application(
UIApplication.shared,
open: url,
sourceApplication: nil,
annotation: [UIApplication.OpenURLOptionsKey.annotation])
}
//create a function for present root view controller in AppDelegate create var window: UIWindow?
var appDelegateShared: AppDelegate {
return UIApplication.shared.delegate as? AppDelegate ?? AppDelegate()
}
create a class for Facebook login
class WFacebookManager: NSObject {
typealias FBCallback = (Bool, Any?) -> Void
var handler: FBCallback?
static let shared: WFacebookManager = WFacebookManager()
public func loginWithFacebook(completion: @escaping FBCallback ) {
handler = completion
let fbLoginManager: LoginManager = LoginManager()
fbLoginManager.logOut()
let presentView = appDelegateShared.window?.rootViewController!
fbLoginManager.logIn(permissions: ["public_profile", "email"], from: presentView) { (result, error) -> Void in
if error == nil {
if (result?.isCancelled)! {
self.handler?(false, nil)
return
} else if AccessToken.current != nil {
let values = "id, name, first_name, last_name, picture.type(large), email"
let request = GraphRequest(graphPath: "me", parameters: ["fields": values])
request.start(completionHandler: { (_, result, error) in
self.handler?(error == nil, result)
})
}
} else {
self.handler?(false, nil)
}
}
}
}
// on your action call function then get login data
@IBAction func loginWithFacebook(_ sender: Any) {
WFacebookManager.shared.loginWithFacebook { (success, data) in
if let data = data as? [String: Any], success {
print (data)
}
}
}