美文网首页Flutterflutterflutter
Flutter快速实现苹果账号登录

Flutter快速实现苹果账号登录

作者: 前端技术小咖 | 来源:发表于2021-04-20 21:42 被阅读0次

    为了提升用户体验,使用三方登录APP的功能怎么能少呢,但是苹果的AppStore有一个很变态的要求,接入其他三方登录的话,要求必须也要接入苹果登录。面对这么变态的要求,作为一个有实力的码农怎么能拒绝呢!
    下面为大家介绍一个好用的Flutter插件Sign in With Apple,可以帮助我们快速的接入苹果账号功能,插件的英文文档讲的比较详细了,英文好的同学可以直接参阅英文文档集成。

    一. 集成插件

    1.1 将Sign in With Apple插件添加到项目中

    在项目的pubspec.yaml文件中添加sign_in_with_apple插件的依赖,如果您使用的Flutter SDK 1.x版本请添加依赖版本2.5.4

    sign_in_with_apple: ^2.5.4
    

    如果您使用的Flutter SDK为2.x,请使用最新版本,当前最新版本3.0.0

    sign_in_with_apple: ^3.0.0
    
    1.2 添加登录代码
    SignInWithAppleButton(
      onPressed: () async {
        final credential = await SignInWithApple.getAppleIDCredential(
          scopes: [
            AppleIDAuthorizationScopes.email,
            AppleIDAuthorizationScopes.fullName,
          ],
        );
    
        if (credential != null) {
            debugPrint("facebook userInfo : userId=${credential.userIdentifier}   email=${credential.email}  giveName=${credential.givenName}   familyName=${credential.familyName}");
        }
      },
    );
    
    1.3 开启 Sign in With Apple Capabilities

    使用XCode打开项目后,按照以下图片上的步骤添加 Sign in With Apple Capabilities:



    成功添加 Sign in With Apple能力后,可以在下面的列表中就代表添加成功了,如下图:


    相关文章

      网友评论

        本文标题:Flutter快速实现苹果账号登录

        本文链接:https://www.haomeiwen.com/subject/wmnglltx.html