Xamarin:最新 FB 问题 API
Xamarin: Issue with latest FB API
最新FB登录API有3个参数
public unsafe virtual void LogInWithReadPermissions (string[] permissions, UIViewController fromViewController, [BlockProxy (typeof(Trampolines.NIDLoginManagerRequestTokenHandler))] LoginManagerRequestTokenHandler handler)
我正在使用 MVVMCross。对于 fb 登录,我尝试创建一个我所在的视图的实例,并将其作为参数传递给 LogInWithReadPermissions()
VIEWMODEL:
private async void DoFacebookSignIn()
{
try
{
await facebookService. Login();
DoAutoLogin();
}
}
服务:
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;
}
但是它失败了,当我调用这个函数时,我需要从 Viewmodel 传递视图信息吗?如何从视图模型传递视图实例?有人可以帮忙吗?
更新
服务失败:
函数LogInWithReadPermissionsAsync()
第 3 行:(LoginManager.LogInWithReadPermissions...)
没有给出任何错误。它只是崩溃。
Facebook API 版本:"Xamarin.Facebook.iOS" version="4.13.1"
更新
删除了未使用的代码。
我找到了解决方案。
代码很好我只需要通过添加
'Whitelist Facebook Servers for Network Requests'
<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>
如 Xamarin Facebook iOS SDK here.
中所述
最新FB登录API有3个参数
public unsafe virtual void LogInWithReadPermissions (string[] permissions, UIViewController fromViewController, [BlockProxy (typeof(Trampolines.NIDLoginManagerRequestTokenHandler))] LoginManagerRequestTokenHandler handler)
我正在使用 MVVMCross。对于 fb 登录,我尝试创建一个我所在的视图的实例,并将其作为参数传递给 LogInWithReadPermissions()
VIEWMODEL:
private async void DoFacebookSignIn()
{
try
{
await facebookService. Login();
DoAutoLogin();
}
}
服务:
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;
}
但是它失败了,当我调用这个函数时,我需要从 Viewmodel 传递视图信息吗?如何从视图模型传递视图实例?有人可以帮忙吗?
更新
服务失败:
函数LogInWithReadPermissionsAsync()
第 3 行:(LoginManager.LogInWithReadPermissions...)
没有给出任何错误。它只是崩溃。 Facebook API 版本:"Xamarin.Facebook.iOS" version="4.13.1"
更新 删除了未使用的代码。
我找到了解决方案。
代码很好我只需要通过添加
'Whitelist Facebook Servers for Network Requests'<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>
如 Xamarin Facebook iOS SDK here.
中所述