Xamarin:最新的FB API问题

The*_*per 6 facebook xamarin.ios facebook-graph-api xamarin xamarin-studio

最新的FB登录API有三个参数

public unsafe virtual void LogInWithReadPermissions (string[] permissions, UIViewController fromViewController, [BlockProxy (typeof(Trampolines.NIDLoginManagerRequestTokenHandler))] LoginManagerRequestTokenHandler handler)
Run Code Online (Sandbox Code Playgroud)

我正在使用MVVMCross.对于fb登录,我尝试创建了我所在视图的实例,并将其作为LogInWithReadPermissions()的参数传递

视图模型:

private async void DoFacebookSignIn()
        {
            try 
            {               
                await facebookService. Login();
                DoAutoLogin();
            }
}
Run Code Online (Sandbox Code Playgroud)

服务:

private readonly string[] permitions = new string[] { "email", "public_profile" };    
public async System.Threading.Tasks.Task LogIn()
            {
    LoginManager.LogInWithReadPermissionsAsync (permitions);

                LoginManagerLoginResult result = await LogInWithReadPermissionsAsync();

                if (result.IsCancelled)
                {
                    ServiceFactory.UserMessageService.ShowToast("Facebook login is canceled");
                }
            }

        private Task<LoginManagerLoginResult> LogInWithReadPermissionsAsync()
            {
                var tcs = new TaskCompletionSource<LoginManagerLoginResult> ();
                LoginManager.LogInWithReadPermissions (permitions,null, (LoginManagerLoginResult result, NSError error) =>
                {
                    if(error.IsNotNull ())
                    {
                        tcs.SetException (new IosErrorException(error));
                    } else 
                    {
                        tcs.SetResult (result);
                    }
                });

                return tcs.Task;
            }
Run Code Online (Sandbox Code Playgroud)

但它失败了,当我调用这个函数时,我是否需要从Viewmodel传递视图信息?如何从视图模型传递视图实例?有人可以帮忙吗?

UPDATE

它在服务上失败了:

功能线LogInWithReadPermissionsAsync() 3:(LoginManager.LogInWithReadPermissions...)

没有给出任何错误.它只是崩溃了.Facebook API版本:"Xamarin.Facebook.iOS"version ="4.13.1"

更新 删除未使用的代码.

The*_*per 1

我得到了解决方案。

代码很好,我只需要通过添加“将网络请求的 Facebook 服务器列入白名单”即可

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>facebook.com</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>                
            <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
            <false/>
        </dict>
        <key>fbcdn.net</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
            <false/>
        </dict>
        <key>akamaihd.net</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
            <false/>
        </dict>
    </dict>
</dict>

If you're recompiling with iOS SDK 9.0, add the following to your application's plist if you're using a version of the SDK v4.5 or older:

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>fbapi</string>
    <string>fbapi20130214</string>
    <string>fbapi20130410</string>
    <string>fbapi20130702</string>
    <string>fbapi20131010</string>
    <string>fbapi20131219</string>    
    <string>fbapi20140410</string>
    <string>fbapi20140116</string>
    <string>fbapi20150313</string>
    <string>fbapi20150629</string>
    <string>fbauth</string>
    <string>fbauth2</string>
    <string>fb-messenger-api20140430</string>
</array>
If you're using Facebook.MessengerShareKit from versions older than the v4.6 release, also add:

<string>fb-messenger-platform-20150128</string>
<string>fb-messenger-platform-20150218</string>
<string>fb-messenger-platform-20150305</string>
If you're using v4.6.0 of the SDK, you only need to add:

<key>LSApplicationQueriesSchemes</key>
<array>
        <string>fbapi</string>
        <string>fb-messenger-api</string>
        <string>fbauth2</string>
        <string>fbshareextension</string>
</array>
Run Code Online (Sandbox Code Playgroud)

正如 Xamarin Facebook iOS SDK 中所述