Xamarin:发布最新的FB API [英] Xamarin: Issue with latest FB API

查看:197
本文介绍了Xamarin:发布最新的FB API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  public unsafe virtual void LogInWithReadPermissions(string [] permissions,UIViewController fromViewController,[BlockProxy (typeof(Trampolines.NIDLoginManagerRequestTokenHandler))] LoginManagerRequestTokenHandler处理程序

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

VIEWMODEL:

  private async void DoFacebookSignIn()
{
try
{
await facebookService。登录();
DoAutoLogin();
}
}

SERVICE: p>

  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登录被取消);
}
}

私人任务< 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;
}

但是它的失败,我需要从Viewmodel传递查​​看信息,当我我打电话给这个func?如何从视图模型传递视图实例?有人可以帮忙吗?



更新



服务失败: p>

func LogInWithReadPermissionsAsync()
line3:(LoginManager.LogInWithReadPermissions ...)



,不会出现任何错误。它刚刚崩溃
Facebook API版本:Xamarin.Facebook.iOSversion =4.13.1



更新
删除未使用的代码。

解决方案

我有解决方案。



代码很好,只需要通过添加

 < key> NSAppTransportSecurity< / key>将Facebook网络请求的白名单 
< 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>

如果您正在使用iOS SDK 9.0重新编译,如果您使用SDK v4.5或更旧的版本,请将以下内容添加到应用程序的plist中:

< ;键> LSApplicationQueriesSchemes< /密钥GT;
< 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>
如果您使用的版本比v4.6版本更早使用Facebook.MessengerShareKit,还可以添加:

< string> fb-messenger-platform-20150128< / string>
< string> fb-messenger-platform-20150218< / string>
< string> fb-messenger-platform-20150305< / string>
如果您使用SDK的v4.6.0,则只需要添加:

< key> LSApplicationQueriesSchemes< / key>
< array>
< string> fbapi< / string>
< string> fb-messenger-api< / string>
< string> fbauth2< / string>
< string> fbshareextension< / string>
< / array>

如Xamarin Facebook iOS SDK here


Latest FB login API has three parameters

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

I am using MVVMCross. For fb login, I tried created an instance of the view i am in, and pass it as a parameter for LogInWithReadPermissions()

VIEWMODEL:

private async void DoFacebookSignIn()
        {
            try 
            {               
                await facebookService. Login();
                DoAutoLogin();
            }
}

SERVICE:

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;
            }

But its failing, Do i need to pass view info from Viewmodel, when I am calling this func? How to pass view instance from view model ? Can anyone help?

UPDATE

It's failing at the service:

func LogInWithReadPermissionsAsync() line3: (LoginManager.LogInWithReadPermissions...)

without giving any error. Its just crashing. The Facebook API version: "Xamarin.Facebook.iOS" version="4.13.1"

UPDATE Removed unused code.

解决方案

I got the solution.

The code was fine I just needed to 'Whitelist Facebook Servers for Network Requests' by adding

<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>

As mentioned in Xamarin Facebook iOS SDK here.

这篇关于Xamarin:发布最新的FB API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆