Since a few months back Apple does not approve apps that have only social media login (ie not good old fashioned username and password) unless it also has “Sign in with Apple” (SIWA)
All this is probably too new for it to be any good tutorials or examples available, at least I could not find any and I spent quite some time looking. I also spent quite a few hours getting it to work, but here it is:
Solution
I used the plugin cordova-plugin-apple-login (version 1.0.0) so go ahead and install it using:
npm i cordova-plugin-apple-login
ionic cordova plugin add cordova-plugin-apple-login
Note that there is no Ionic Native wrapper for the plugin, so you have to declare it instead of importing it on your page:
declare var SignInWithApple: any;
This is the login function:
loginWithApple() {
SignInWithApple.request({requestedScopes: [ SignInWithApple.Scope.Email, SignInWithApple.Scope.FullName ]})
.then((appleCredential) => {
const credential = new firebase.auth.OAuthProvider('apple.com').credential(appleCredential.identityToken);
this.afAuth.auth.signInWithCredential(credential)
.then((response) => {
console.log('Login successful');
})
.catch((error) => {
console.log(error);
alert('error:' + JSON.stringify(error));
});
});
}
This was done using Ionic 4 / Angular, AngularFire2 5.30 and the cordova-plugin-apple-login 1.0.0
Configuration
You also have to do some configurations…
-> Xcode: Add capability for Sign in with Apple
-> Apple Developer: Add Services id
-> Firebase console: Add Sign-in method for Apple, leave all fields blank if you only use on iOS
If you want to support Android and or Web / PWA, you will need to do some more configuring.
Did this solution help you?
Please comment if it did, or if you had a problem with it. Also if you got it working (or not) using other versions of plugins, frameworks etc or if you found a better solution – it will help others!
P.s. I also posted this solution to Stack Overflow (my first anwer there, yay!)
Please Help,
below is the error I’m getting while using your code
Cannot find name ‘AppleSignInResponse’.
Cannot find name ‘ASAuthorizationAppleIDRequest’.
Cannot find name ‘ASAuthorizationAppleIDRequest’.
I get this error ‘can’t find variable SignInWithApple’ can you help me?
how to enable the same in Android?
Can’t find variable: SignInWithApple error