我正在尝试使用以下插件和包装器在我的 ionic 3 项目上实现苹果登录
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 构建过程中抛出以下错误
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;
任何帮助将不胜感激,谢谢
tsc -v
Version 3.8.3
这对我有用:
- install:
ionic cordova plugin add https://github.com/twogate/cordova-plugin-sign-in-with-apple.git
- 在你的组件中声明 var
declare var cordova:any; // global
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))
}
我希望这个解决方案可以帮助某人。
重要 --> 在设备中测试
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)