更新记录
1.0.0(2026-03-25)
这是一个基于 UTS 语法开发的 uni-app-x iOS 端 Apple 一键登录插件,用于在 iOS 应用中集成 Apple 登录功能,支持获取用户的 Apple 标识符、姓名、邮箱和身份令牌等信息。
- ✅ 支持 iOS 13.0 及以上版本
- ✅ 获取用户 Apple 唯一标识符(userIdentifier)
- ✅ 获取用户姓名信息(givenName、familyName)
- ✅ 获取用户邮箱信息(email)
- ✅ 获取身份令牌(identityToken)
- ✅ 异步回调机制,支持成功和失败处理
平台兼容性
uni-app x(4.57)
| Chrome | Safari | Android | iOS | 鸿蒙 | 微信小程序 |
|---|---|---|---|---|---|
| × | × | × | 13 | × | × |
Apple 一键登录(apple-login)
模块介绍
这是一个基于 UTS 语法开发的 uni-app-x iOS 端 Apple 一键登录插件,用于在 iOS 应用中集成 Apple 登录功能,支持获取用户的 Apple 标识符、姓名、邮箱和身份令牌等信息。
功能特性
- ✅ 支持 iOS 13.0 及以上版本
- ✅ 获取用户 Apple 唯一标识符(userIdentifier)
- ✅ 获取用户姓名信息(givenName、familyName)
- ✅ 获取用户邮箱信息(email)
- ✅ 获取身份令牌(identityToken)
- ✅ 异步回调机制,支持成功和失败处理
技术支持
- 支持平台:仅 iOS(APP-IOS)
- 开发语言:UTS + Swift
- 依赖:iOS AuthenticationServices 框架
使用条件
- iOS 13.0 及以上版本
- HBuilderX 4.31 及以上版本
- uni-app-x 3.1.0 及以上版本
配置说明
Apple Developer 配置
- 登录 Apple Developer 网站
- 在应用标识符(App ID)中启用 "Sign In with Apple" 功能
- 在 HBuilderX 中配置 iOS 原生能力:
- 打开项目设置
- 选择 "原生能力配置"
- 启用 "Sign In with Apple" 选项
API 说明
appleLogin
函数签名:
appleLogin(success: (info: Map<string, any>) => void, fail: (error: string) => void): void
参数说明:
success: 登录成功回调函数,返回包含用户信息的 Map 对象fail: 登录失败回调函数,返回错误信息字符串
| 返回结果(success): | 字段名 | 类型 | 说明 |
|---|---|---|---|
| userIdentifier | string | Apple 用户唯一标识符,用于识别用户 | |
| givenName | string | 用户的名 | |
| familyName | string | 用户的姓 | |
| string | 用户的邮箱 | ||
| identityToken | string | 身份令牌,用于服务器端验证 |
返回结果(fail):
error: 错误信息字符串
使用示例
基本使用
<template>
<view class="container">
<button @click="handleAppleLogin">Apple 一键登录</button>
</view>
</template>
<script setup lang="uts">
// #ifdef APP-IOS
import { appleLogin } from '@/uni_modules/apple-login';
// #endif
const handleAppleLogin = () => {
// #ifdef APP-IOS
appleLogin(
(info) => {
// 登录成功,处理用户信息 info
/*
{
"userIdentifier": "000967.xxxxxxxxxxxxxxxxxxx.0903",
"identityToken": "eyJxxxxxxifQ.eyJpc3MiOxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxnRydWV9.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"email": "xxxxxxxx@qq.com",
"familyName": "张",
"givenName": "三"
}
*/
console.log('Apple 登录成功', info);
// TODO: 将用户信息发送到服务器进行验证和处理
uni.showToast({
title: '登录成功',
icon: 'success'
});
},
(error) => {
// 登录失败,处理错误信息
console.error('Apple 登录失败', error);
uni.showToast({
title: error,
icon: 'none'
});
}
);
// #endif
};
</script>
注意事项
-
iOS 版本限制:该模块仅支持 iOS 13.0 及以上版本,低于此版本的设备将无法使用 Apple 登录功能。
-
用户信息获取:
- 首次登录时,用户可以选择是否共享姓名和邮箱信息
- 后续登录时,可能无法获取到姓名和邮箱信息,只能获取到 userIdentifier
-
userIdentifier 唯一性:
- userIdentifier 是用户的唯一标识符,同一个 Apple ID 在同一个应用中始终返回相同的值
- 可以使用 userIdentifier 来识别和关联用户账号
-
隐私政策:
- 集成 Apple 登录功能时,需要在应用的隐私政策中说明数据使用方式
-
用户体验:
- 建议提供其他登录方式作为备选,以满足不同用户的需求
- 登录按钮的设计应遵循 Apple 的 Human Interface Guidelines
常见问题
Q: 为什么无法获取到用户的姓名和邮箱?
A: 用户在首次登录时可以选择是否共享这些信息,如果用户选择不共享,或者是后续登录,可能无法获取到这些信息。
Q: userIdentifier 会变化吗?
A: userIdentifier 是用户的唯一标识符,同一个 Apple ID 在同一个应用中始终返回相同的值,不会变化。
Q: 如何处理登录失败的情况?
A: 在 fail 回调中处理错误信息,根据不同的错误类型给用户相应的提示。
Q: 可以在模拟器上测试吗?
A: 可以在 iOS 13.0 及以上版本的模拟器上测试 Apple 登录功能。
更新日志
v1.0.0
- 初始版本发布
- 支持 Apple 登录功能
- 支持获取用户标识符、姓名、邮箱和身份令牌
许可证
MIT License

收藏人数:
购买普通授权版(
试用
赞赏(0)
下载 774
赞赏 11
下载 11586243
赞赏 1884
赞赏
京公网安备:11010802035340号