我正在尝试使用以下插件和包装器在我的ionic 3项目中实现与apple的登录
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发布于 2020-08-01 01:57:41
这对我来说很有效:
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))
}我希望这个解决方案能帮助一些人。
重要-->在设备中测试
发布于 2020-07-17 01:10:10
我尝试了您的解决方案,并遇到了与我相同的问题。
我用Apple ID登录的实现在我的ionic 3上运行得很好。
in cordova插件添加cordova- plugin -sign-in-with-apple
//before @component add declare var cordova: any;
async loginWithAppleID() {
await cordova.plugins.SignInWithApple.signin(
{requestedScopes: [0, 1]},
(succ) => {
//get email and full name from Apple ID
console.log(succ)
let userData = {
name: succ.fullName.givenName + ' ' + succ.fullName.familyName,
email: succ.email,
};
// this.AuthApi;
},
(err) => {
console.error(err)
console.log(JSON.stringify(err))
}
)
}发布于 2020-08-17 19:36:14
我也收到了同样的错误。
错误来自small changes in this commit。
使用提交之前的版本为我解决了问题。如果您可以恢复到以前的版本,请尝试以下操作:
npm install @ionic-native/sign-in-with-apple@5.16.0在此之后,ionic build应该会成功。祝好运!
https://stackoverflow.com/questions/60964560
复制相似问题