记录 ionic使用Apple账号登录(是iPhone审核的时候报了一个4.8错误)

上代码

import { Component } from '@angular/core';
import { Platform } from '@ionic/angular';
//这个是iphone登录插件
//这里需要装两个插件
//ionic cordova plugin add cordova-plugin-sign-in-with-apple
//npm i @ionic-native/sign-in-with-apple
import {
  SignInWithApple,
  AppleSignInResponse,
  AppleSignInErrorResponse,
  ASAuthorizationAppleIDRequest,
  SignInWithAppleOriginal
} from '@ionic-native/sign-in-with-apple';

import { from } from 'rxjs';
@Component({
  selector: 'app-tab1',
  templateUrl: 'tab1.page.html',
  styleUrls: ['tab1.page.scss']
})
export class Tab1Page {

  constructor(
    private platform: Platform,
    //开始的时候按照这种方式一直报错
    // private signInWithApple: SignInWithApple
  ) { }
  public str?: string = '8899';
  //大胆一点根据vscode提示,我直接把这个值赋给了自定义的变量
  private signInWithApple: any = SignInWithApple;
  //这个就是存储从apple账号里获取到的一些信息,也就是下面写出的那个返回值示例
  private appleSignInfo: any;
  checkPlatFormIsiOS() {
  //先检查当前平台是不是iphone
    return this.platform.is('iphone') && !this.platform.is('mobileweb');
  }
  clickEvent() {
    if (this.checkPlatFormIsiOS()) {
    //如果是就执行
      alert('i am runing');
      this.str = 'i am runing';
      //开始获取apple账号的信息
      this.signInWithApple.signin({
        requestedScopes: [
          ASAuthorizationAppleIDRequest.ASAuthorizationScopeFullName,
          ASAuthorizationAppleIDRequest.ASAuthorizationScopeEmail
        ]
        //请求scope //全名和email
      })
        .then((res: AppleSignInResponse) => {
        //请求成功
          alert('Send token to apple for verification: ' + res.identityToken);
          alert(JSON.stringify(res));
          this.appleSignInfo = res;
          //	这个是res返回值的格式
          let appleLoginInfo = {
            "email": "",
            "authorizationCode": "",
            "state": "",
            "identityToken": "",
            "fullName": {
              "nickname": "",
              "phoneticRepresentation": {},
              "middleName": "",
              "familyName": "",
              "namePrefix": "",
              "givenName": "",
              "nameSuffix": "",
            },
            "user": ""
          }
          console.log(res);
        })
        .catch((error: AppleSignInErrorResponse) => {
        //请求失败
          alert(error.code + ' ' + error.localizedDescription);
          console.error(error);
        });
    } else {
    //如果不是iphone
    //把页面上的提示字符改一下
      this.str = 'this is not iphone';
    }
  }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值