Xamarin: problem with latest FB API

The last 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. To login fb I tried to create an instance of the view I'm am in and pass it as a parameter to 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 crashes, do I need to pass view information from the Viewmodel when I call this function? How to pass an instance of a view from a view model? Can anyone help?

UPDATE

Service Error:

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

without any errors. Its just a glitch. API version for Facebook: "Xamarin.Facebook.iOS" version = "4.13.1"

UPDATE Removed unused code.

+6
source share
1 answer

I got a solution.

The code was ok, I just needed the “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 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 the Xamarin Facebook iOS SDK here .

+1
source

All Articles