I have created a project on Xamarin forms with reference to this link for "Sign in with apple" functionality
https://learn.microsoft.com/en-us/samples/xamarin/xamarin-forms-samples/signinwithapple/
and while testing it on simulator and as well as on device, I am getting this exception error message while testing Sign in with Apple functionality
"The operation couldn’t be completed (com.apple.AuthenticationServices.AuthorizationError error 1000.)"
below is my sample code -
[assembly: Xamarin.Forms.Dependency(typeof(AppleSignInServiceiOS))]
namespace MyCaseStatus.iOS.Services
{
public class AppleSignInServiceiOS : IAppleSignInService
{
//#if __IOS__13
AuthManager authManager;
//#endif
bool Is13 => UIDevice.CurrentDevice.CheckSystemVersion(13, 0);
WebAppleSignInService webSignInService;
public AppleSignInServiceiOS()
{
if (!Is13)
webSignInService = new WebAppleSignInService();
}
public async Task<AppleAccount> SignInAsync()
{
// Fallback to web for older iOS versions
if (!Is13)
return await webSignInService.SignInAsync();
AppleAccount appleAccount = default;
try
{
//#if __IOS__13
var provider = new ASAuthorizationAppleIdProvider();
var req = provider.CreateRequest();
authManager = new AuthManager(UIApplication.SharedApplication.KeyWindow);
req.RequestedScopes = new[] { ASAuthorizationScope.FullName, ASAuthorizationScope.Email };
var controller = new ASAuthorizationController(new[] { req });
controller.Delegate = authManager;
controller.PresentationContextProvider = authManager;
controller.PerformRequests();
var creds = await authManager.Credentials;
if (creds == null)
return null;
appleAccount = new AppleAccount();
//appleAccount.IdToken = JwtToken.Decode(new NSString(creds.IdentityToken, NSStringEncoding.UTF8).ToString());
appleAccount.Email = creds.Email;
appleAccount.UserId = creds.User;
appleAccount.Name = NSPersonNameComponentsFormatter.GetLocalizedString(creds.FullName, NSPersonNameComponentsFormatterStyle.Default, NSPersonNameComponentsFormatterOptions.Phonetic);
appleAccount.RealUserStatus = creds.RealUserStatus.ToString();
//#endif
}
catch (Exception ex) {
string Excep = ex.Message;
}
return appleAccount;
}
public bool Callback(string url) => true;
//Task<AppleAccount> IAppleSignInService.SignInAsync()
//{
// throw new NotImplementedException();
//}
}
//#if __IOS__13
class AuthManager : NSObject, IASAuthorizationControllerDelegate, IASAuthorizationControllerPresentationContextProviding
{
public Task<ASAuthorizationAppleIdCredential> Credentials
=> tcsCredential?.Task;
TaskCompletionSource<ASAuthorizationAppleIdCredential> tcsCredential;
UIWindow presentingAnchor;
public AuthManager(UIWindow presentingWindow)
{
tcsCredential = new TaskCompletionSource<ASAuthorizationAppleIdCredential>();
presentingAnchor = presentingWindow;
}
public UIWindow GetPresentationAnchor(ASAuthorizationController controller)
=> presentingAnchor;
[Export("authorizationController:didCompleteWithAuthorization:")]
public void DidComplete(ASAuthorizationController controller, ASAuthorization authorization)
{
var creds = authorization.GetCredential<ASAuthorizationAppleIdCredential>();
tcsCredential?.TrySetResult(creds);
}
[Export("authorizationController:didCompleteWithError:")]
public void DidComplete(ASAuthorizationController controller, NSError error)
=> tcsCredential?.TrySetException(new Exception(error.LocalizedDescription));
}
//#endif
}
I have checked all possible solution for this error but still getting same error every time.
can anyone please help or provide any solution for this error.
I will be very thankful if anyone can provide me a link or reference for solving this error.
Thanks.