private Tuple <string, string> verifyFacebookFromSerttings() { Tuple <string, string> signedInResult = Tuple.Create <string, string>(string.Empty, string.Empty); AutoResetEvent taskCompleted = new AutoResetEvent(false); var options = new AccountStoreOptions() { FacebookAppId = "1626108114272416" }; options.SetPermissions(ACFacebookAudience.Friends, new[] { "public_profile", "email" }); ACAccountStore accountStore = new ACAccountStore(); var accountType = accountStore.FindAccountType(ACAccountType.Facebook); var facebookAccounts = accountStore.FindAccounts(accountType); if ((facebookAccounts == null) || (facebookAccounts.Length == 0)) { accountStore.RequestAccess(accountType, options, (granted, error2) => { if (granted) { facebookAccounts = accountStore.FindAccounts(accountType); } taskCompleted.Set(); }); taskCompleted.WaitOne(); } if ((facebookAccounts != null) && (facebookAccounts.Length > 0)) { var facebookAccount = facebookAccounts[0]; accountStore.RenewCredentials(facebookAccount, (result, error1) => { if (result == ACAccountCredentialRenewResult.Renewed) { var id = parseFacebookUserIdFromSettings(facebookAccount); if (!string.IsNullOrEmpty(id)) { signedInResult = Tuple.Create <string, string>(facebookAccount.Credential.OAuthToken, id); } } taskCompleted.Set(); }); } else { taskCompleted.Set(); } taskCompleted.WaitOne(); return(signedInResult); }
public static Task <ACAccountCredentialRenewResult> RenewCredentialsAsync(this ACAccountStore store, ACAccount account) { TaskCompletionSource <ACAccountCredentialRenewResult> tcs = new TaskCompletionSource <ACAccountCredentialRenewResult> (); store.RenewCredentials(account, delegate(ACAccountCredentialRenewResult arg1, NSError arg2) { if (arg2 != null) { tcs.SetException(new NSErrorException(arg2)); } else { tcs.SetResult(arg1); } }); return(tcs.Task); }