首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Apple - Ionic 3登录

使用Apple - Ionic 3登录
EN

Stack Overflow用户
提问于 2020-04-01 14:01:51
回答 4查看 1.3K关注 0票数 3

我正在尝试使用以下插件和包装器在我的ionic 3项目中实现与apple的登录

代码语言:javascript
复制
ionic cordova plugin add cordova-plugin-sign-in-with-apple
npm i --save @ionic-native/sign-in-with-apple

插件文档中描述的实现

代码语言:javascript
复制
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构建过程中抛出以下错误

代码语言:javascript
复制
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;

感谢您的帮助,谢谢!

代码语言:javascript
复制
tsc -v 
Version 3.8.3
EN

回答 4

Stack Overflow用户

发布于 2020-08-01 01:57:41

这对我来说很有效:

  1. install:

ionic cordova plugin add https://github.com/twogate/cordova-plugin-sign-in-with-apple.git

  1. 在component

中声明var

declare var cordova:any; // global

代码语言:javascript
复制
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))
}

我希望这个解决方案能帮助一些人。

重要-->在设备中测试

票数 2
EN

Stack Overflow用户

发布于 2020-07-17 01:10:10

我尝试了您的解决方案,并遇到了与我相同的问题。

我用Apple ID登录的实现在我的ionic 3上运行得很好。

in cordova插件添加cordova- plugin -sign-in-with-apple

代码语言:javascript
复制
//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))
          }
        )
      }
票数 1
EN

Stack Overflow用户

发布于 2020-08-17 19:36:14

我也收到了同样的错误。

错误来自small changes in this commit

使用提交之前的版本为我解决了问题。如果您可以恢复到以前的版本,请尝试以下操作:

代码语言:javascript
复制
npm install @ionic-native/sign-in-with-apple@5.16.0

在此之后,ionic build应该会成功。祝好运!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60964560

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档