ios - FBSDKLoginKit 在登录和确认页面后不重定向我的应用程序
<p><p>我正在使用 Swift 3.0 集成 Facebook SDK 4.15.1。</p>
<p>我已按照链接中提到的所有步骤进行操作
<a href="https://developers.facebook.com/docs/ios/getting-started" rel="noreferrer noopener nofollow">Getting started with iOS</a> ,我可以登录 Facebook 并使用 Safari 浏览器进行授权,但之后该控件没有返回到我的应用程序并显示空白页面。但是当我按下完成按钮时,委托(delegate)方法 <code>didCompleteWith 结果:</code> 被调用并出现错误 <code>OAuthException</code>。在我的应用程序中也永远不会调用 <code>OpenURL</code> 方法。我还彻底验证了我的属性列表文件和应用程序 ID,包标识符或应用程序 ID 没有错误。 </p>
<p>在设备 < iOS 9.0 中不显示空白页。</p>
<p>感谢任何帮助。</p>
<p>以下是我在 Swift 3.0 中用于登录和获取访问 token 的代码,</p>
<pre><code>AppDelegate.swift
import UIKit
import CoreData
import FBSDKCoreKit
import FBSDKLoginKit
import FBSDKShareKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate{
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: ?) -> Bool {
FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
return true
}
func application(application: UIApplication,
openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, open: url as URL!, sourceApplication: sourceApplication, annotation: annotation)
}
func applicationDidBecomeActive(_ application: UIApplication) {
FBSDKAppEvents.activateApp()
}
</code></pre>
<p>ViewController.swift</p>
<pre><code>import UIKit
import FBSDKLoginKit
import FBSDKCoreKit
class ViewController: UIViewController, GIDSignInUIDelegate, FBSDKLoginButtonDelegate{
public func loginButtonDidLogOut(_ loginButton: FBSDKLoginButton!) {
}
let loginView : FBSDKLoginButton = FBSDKLoginButton()
self.view.addSubview(loginView)
loginView.center = self.view.center
loginView.readPermissions = ["public_profile", "email", "user_friends"]
loginView.delegate = self
}
func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!) {
if error == nil {
print("Success")
let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: ["fields":"id,interested_in,gender,birthday,email,age_range,name,picture.width(480).height(480)"])
graphRequest.start(completionHandler: { (connection, result, error) -> Void in
if ((error) != nil)
{
print("Error: \(error)")
}
else
{
print("fetched user: \(result)")
}
})
}else{
print("Failure")
}
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我已通过在属性列表中添加以下传输安全 key 来解决此问题。</p>
<pre><code><key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>facebook.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
<key>fbcdn.net</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
<key>akamaihd.net</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
</dict>
</dict>
</code></pre></p>
<p style="font-size: 20px;">关于ios - FBSDKLoginKit 在登录和确认页面后不重定向我的应用程序,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/39701394/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/39701394/
</a>
</p>
页:
[1]