You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Flutter中实现Sign in With Apple功能?求可行方案

在Flutter中实现Sign in With Apple的方案

不需要自己通过Platform Channel调用原生API,社区有成熟易用的Flutter包可直接使用,完全适配新手需求。

推荐的Flutter包

  • sign_in_with_apple:这是官方推荐的维护活跃的包,完美适配iOS和macOS,支持Sign in With Apple的所有核心功能,包括获取用户信息、令牌验证等。

基础实现步骤

  1. 在pubspec.yaml中添加依赖:
    dependencies:
      sign_in_with_apple: ^5.0.0 # 请使用最新版本号
    
  2. 执行flutter pub get安装依赖。
  3. iOS端配置:
    • 打开Xcode中的iOS项目,在Target > Signing & Capabilities中添加Sign in With Apple能力。
    • 确保你的Bundle ID已在Apple开发者后台开启Sign in With Apple服务。
  4. 核心调用代码示例:
    import 'package:sign_in_with_apple/sign_in_with_apple.dart';
    
    Future<void> signInWithApple() async {
      try {
        final credential = await SignInWithApple.getAppleIDCredential(
          scopes: [
            AppleIDAuthorizationScopes.email,
            AppleIDAuthorizationScopes.fullName,
          ],
        );
    
        // 获取到 credential 后,可将令牌、用户信息传给后端做验证或存储
        print('Apple ID Token: ${credential.identityToken}');
        print('用户邮箱: ${credential.email}');
        print('用户姓名: ${credential.givenName} ${credential.familyName}');
      } catch (e) {
        print('登录失败: $e');
      }
    }
    

额外提示

  • 该包的内置文档包含详细的配置指引,包括后端如何验证Apple令牌的方法,新手可以按步骤逐步操作。
  • 若需支持Android平台,该包会自动引导用户通过浏览器完成授权流程,无需额外复杂配置。

内容的提问来源于stack exchange,提问作者Abins Musthafa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 19:18:14