首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Xamarin:最新的FB问题

Xamarin:最新的FB问题
EN

Stack Overflow用户
提问于 2016-08-26 15:32:32
回答 1查看 864关注 0票数 6

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

代码语言:javascript
复制
public unsafe virtual void LogInWithReadPermissions (string[] permissions, UIViewController fromViewController, [BlockProxy (typeof(Trampolines.NIDLoginManagerRequestTokenHandler))] LoginManagerRequestTokenHandler handler)

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

VIEWMODEL:

代码语言:javascript
复制
private async void DoFacebookSignIn()
        {
            try 
            {               
                await facebookService. Login();
                DoAutoLogin();
            }
}

服务:

代码语言:javascript
复制
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;
            }

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

更新

在服务上失败了:

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

不犯任何错误。只是崩溃而已。Facebook版本:"Xamarin.Facebook.iOS“version="4.13.1”

更新删除了未使用的代码。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-09-19 18:11:16

我找到解决办法了。

代码很好,我只需要“为网络请求白名单Facebook服务器”

代码语言:javascript
复制
<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>

正如iOS 这里中所提到的。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39169856

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档