npm i --save nativescript-ns-apple-signin
- 版本:1.0.4
- GitHub: https://github.com/tungtranuit/nativescript-ns-apple-signin
- NPM: https://npmjs.net.cn/package/nativescript-ns-apple-signin
- 下载量
- 昨天:0
- 上周:0
- 上个月:0
nativescript-ns-apple-signin
Apple 登录,适用于 NativeScript
我的 LinkedIn https://www.linkedin.com/in/tungtranuit/
轻松获取用户信息,使用 Apple 登录。
您可以获取以下信息:用户、电子邮件、真实用户状态、身份令牌、授权码、全名(给定名称、姓氏、中间名、名称前缀、名称后缀、昵称、音译名称)...
{
user: user ,
email: email,
fullName:{
givenName
familyName
middleName
namePrefix
nameSuffix
nickname
phoneticRepresentation
},
realUserStatus: realUserStatus,
identityToken: identityToken,
authCode: authCode
}
从 https://github.com/EddyVerbruggen/nativescript-apple-sign-in 重新编写插件。
先决条件 / 要求
访问 Apple 开发者网站 并创建一个新的应用程序标识符,启用“Apple 登录”功能。确保您使用该应用程序标识符对应用程序进行签名。打开应用程序的 App_Resources/iOS 文件夹,并将以下内容(或追加)添加到名为 app.entitlements 的文件中。
<key>com.apple.developer.applesignin</key>
<array>
<string>Default</string>
</array>
安装
tns plugin add nativescript-ns-apple-signin
配置
使用方法
tns plugin add nativescript-ns-apple-signin
API
isSignInWithAppleSupported
Apple 登录从 iOS 13 开始添加,所以确保在您的应用程序中显示“Apple 登录”按钮之前调用此函数。在 iOS < 13 和 Android 上,这将返回 false
。
import { isSignInWithAppleSupported } from "nativescript-ns-apple-signin";
const supported: boolean = isSignInWithAppleSupported();
signInWithApple
如果您知道该设备支持“Apple 登录”,则可以允许用户自行登录(例如,在按下漂亮的按钮后)。
import { signInWithApple } from "nativescript-ns-apple-signin";
signInWithApple(
{
scopes: ["EMAIL","FULLNAME"]
})
.then(credential => {
console.log("Signed in, user: " + credential.user);
console.log("Signed in, user: " + credential.email);
console.log("Signed in, user: " + JSON.stringify(credential.fullName));
this.user = credential.user;
})
.catch(err => console.log("Error signing in: " + err));
getSignInWithAppleState
如果您想了解用户当前的登录状态,您可以传递之前获取的 user
(id)。
import { getSignInWithAppleState } from "nativescript-apple-sign-in";
const user: string = "the id you got back from the signInWithApple function";
getSignInWithAppleState(user)
.then(state => console.log("Sign in state: " + state))
.catch(err => console.log("Error getting sign in state: " + err));
许可
Apache 许可证版本 2.0,2004 年 1 月