gpt4 book ai didi

facebook - Xamarin.Auth iOS9 身份验证 SSL 错误

转载 作者:行者123 更新时间:2023-11-30 05:23:51 25 4
gpt4 key购买 nike

我刚刚将 XCode 更新到 7.0 (7A220),这会将我的模拟器带到 iOS9。

从那一刻起,我无法从模拟器成功执行任何 OAUTH 调用。我尝试了所有模型,从我的应用程序到“示例 Xamarin.Auth 应用程序”。

答案总是一样的:

“认证错误

发生 SSL 错误,无法与服务器建立安全连接"

Exception I get

代码是标准代码,我只更改了我的 AppID。相同的代码适用于同一应用程序的 Android 版本!

var auth = new OAuth2Authenticator (
clientId: "my app id",
scope: "",
authorizeUrl: new Uri ("https://m.facebook.com/dialog/oauth/"),
redirectUrl: new Uri ("http://www.facebook.com/connect/login_success.html"));

auth.AllowCancel = allowCancel;

// If authorization succeeds or is canceled, .Completed will be fired.
auth.Completed += (s, e) =>
{
// We presented the UI, so it's up to us to dismiss it.
dialog.DismissViewController (true, null);

if (!e.IsAuthenticated) {
facebookStatus.Caption = "Not authorized";
dialog.ReloadData();
return;
}

// Now that we're logged in, make a OAuth2 request to get the user's info.
var request = new OAuth2Request ("GET", new Uri ("https://graph.facebook.com/me"), null, e.Account);
request.GetResponseAsync().ContinueWith (t => {
if (t.IsFaulted)
facebookStatus.Caption = "Error: " + t.Exception.InnerException.Message;
else if (t.IsCanceled)
facebookStatus.Caption = "Canceled";
else
{
var obj = JsonValue.Parse (t.Result.GetResponseText());
facebookStatus.Caption = "Logged in as " + obj["name"];
}

dialog.ReloadData();
}, uiScheduler);
};

UIViewController vc = auth.GetUI ();
dialog.PresentViewController (vc, true, null);

IOS9模拟器可以上网,所以不是“连通性问题”。我也尝试使用 Facebook SDK,同样的错误。会不会是证书问题?

谢谢

最佳答案

要解决此问题,只需将这些行添加到您的 Info.plist 文件中:

<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<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>

如果您不关心域的额外规则,您可以简单地添加:

 <key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key> <true/> </dict>

注意:您必须清理并重建项目才能看到它使用这些新设置运行!

关于facebook - Xamarin.Auth iOS9 身份验证 SSL 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32745523/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com