使用 Apple 登录 - Ionic 3 [英] Sign In With Apple - Ionic 3
本文介绍了使用 Apple 登录 - Ionic 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用以下插件和包装器在我的 ionic 3 项目上使用苹果实现登录
Am trying to implement sign in with apple on my ionic 3 project using the following plugin and wrapper
ionic cordova plugin add cordova-plugin-sign-in-with-apple
npm i --save @ionic-native/sign-in-with-apple
插件文档中描述的实现
import { SignInWithApple, AppleSignInResponse, AppleSignInErrorResponse, ASAuthorizationAppleIDRequest } from '@ionic-native/sign-in-with-apple/ngx';
constructor(private signInWithApple: SignInWithApple) { }
this.signInWithApple.signin({
requestedScopes: [
ASAuthorizationAppleIDRequest.ASAuthorizationScopeFullName,
ASAuthorizationAppleIDRequest.ASAuthorizationScopeEmail
]
})
.then((res: AppleSignInResponse) => {
// https://developer.apple.com/documentation/signinwithapplerestapi/verifying_a_user
alert('Send token to apple for verification: ' + res.identityToken);
console.log(res);
})
.catch((error: AppleSignInErrorResponse) => {
alert(error.code + ' ' + error.localizedDescription);
console.error(error);
});
cordova ios构建过程中抛出如下错误
The following error is thrown during cordova ios build process
typescript: node_modules/@ionic-native/sign-in-with-apple/ngx/index.d.ts, line: 6
Initializers are not allowed in ambient contexts.
L5: export declare class ASAuthorizationAppleIDRequest {
L6: static readonly ASAuthorizationScopeFullName = 0;
L7: static readonly ASAuthorizationScopeEmail = 1;
任何帮助将不胜感激,谢谢
Any help would be appreciated, thanks
tsc -v
Version 3.8.3
推荐答案
这对我有用:
- 安装:
ionic cordova 插件添加 https://github.com/twogate/cordova-plugin-sign-in-with-apple.git
- 在你的组件中声明 var
声明 var cordova:any;//全局
cordova.plugins.SignInWithApple.signin(
{ requestedScopes: [0, 1] },
function(response){
console.log(response)
alert(JSON.stringify(response))
},
function(err){
console.error(err)
console.log(JSON.stringify(err))
}
我希望这个解决方案可以帮助某人.
I hope this solution can help someone.
重要 -->在设备中测试
IMPORTANT --> Test in device
这篇关于使用 Apple 登录 - Ionic 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文