我在我的ios应用程序中使用facebook登录API(SDK version Optional("4.1.0")
)Swift
。我在我的视图控制器上放置了fb登录按钮,当用户点击它时 - 它会在safari中打开Facebook登录面板。当用户将凭据,并点击登录 - 他看到弹出消息有一个问题:“在APP_NAME中打开此页面”,同时在Swift中使用facebook登录api
Open this page in APP_NAME?
Cancel OPEN
我想摆脱这一点,并直接打开应用程序。 我的代码来处理按钮的行为是这样的:
class ViewController: UIViewController, FBSDKLoginButtonDelegate {
@IBOutlet weak var fbLoginButton: FBSDKLoginButton!
override func viewDidLoad() {
super.viewDidLoad()
fbLoginButton.readPermissions = ["public_profile", "email"]
fbLoginButton.layer.cornerRadius = 5
fbLoginButton.delegate = self
self.fbLoginButton.delegate = self
FBSDKProfile.enableUpdates(onAccessTokenChange: true)
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if (FBSDKAccessToken.current() != nil){
let tokenAsAParam = [
"access_token":FBSDKAccessToken.current().tokenString!
]
let loginManager = FBSDKLoginManager()
FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, last_name, email"]).start(completionHandler: { (connection, result, error) -> Void in
if (error == nil){
let data:[String:AnyObject] = result as! [String : AnyObject]
let defaults = UserDefaults.standard
let firstName:String = data["first_name"] as! String!
defaults.set(firstName, forKey: "facebook_display_name")
defaults.synchronize()
}else {
print("fb error")
}
})
Alamofire.request("\(serverURL)/auth/facebook", method: .post, parameters: tokenAsAParam)
.validate()
.responseJSON { response in
switch(response.result) {
case .success:
self.performSegue(withIdentifier: "openMainApp", sender: self)
break
case .failure:
print(response.result.error)
loginManager.logOut()
break
}
}
}
在上面的代码,我获取从Facebook用户的数据并发送令牌到我的web服务,以验证有用户是否是真的还是假的并做一些后端的东西。
我Info.plist文件是:
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>fbXXXXXXXXXX</string>
</array>
</dict>
</array>
<key>FacebookAppID</key>
<string>2XXXXXXXXXXX</string>
<key>FacebookDisplayName</key>
<string>xxxxxxxx</string>
<key>LSApplicationCategoryType</key>
<string></string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fb-messenger-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>
</array>
而且,在我的appDelegate我有以下几种方法:
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
print("SDK version \(FBSDKSettings .sdkVersion())")
...
return true
}
func application(_ application: UIApplication,
open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, open: url, sourceApplication: sourceApplication, annotation: annotation)
}
// [END openurl]
@available(iOS 9.0, *)
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(app, open: url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String?, annotation: options[UIApplicationOpenURLOptionsKey.annotation])
}
但它仍然表明这种怪异的poppup而不是正常打开的应用程式。
有谁知道我能做些什么来解决这个问题?