npm i --save nativescript-apple-sign-in-knotes
- 版本:1.1.1
- GitHub: https://github.com/EddyVerbruggen/nativescript-apple-sign-in
- NPM: https://npmjs.net.cn/package/nativescript-apple-sign-in-knotes
- 下载
- 昨天:0
- 上周:6
- 上个月:35
使用Apple登录,适用于NativeScript
要求
- 访问苹果开发者网站并创建一个新的应用标识符,启用“使用Apple登录”功能。确保使用该应用标识符对您的应用程序进行签名,并使用配置文件。
- 打开您的应用程序的
App_Resources/iOS
文件夹,并将以下内容添加到名为app.entitlements
的文件中(或追加)。
安装
tns plugin add nativescript-apple-sign-in
示例应用程序
如果您遇到困难或想快速了解如何使用此功能,请查看示例应用程序
git clone https://github.com/EddyVerbruggen/nativescript-apple-sign-in
cd nativescript-apple-sign-in/src
npm run demo.ios
API
isSignInWithAppleSupported
“使用Apple登录”是在iOS 13中添加的,所以在您的应用程序中显示“使用Apple登录”按钮之前,请确保调用此函数。在iOS < 13和Android上,此函数将返回false
。
import { isSignInWithAppleSupported } from "nativescript-apple-sign-in";
const supported: boolean = isSignInWithAppleSupported();
signInWithApple
现在您知道“使用Apple登录”在此设备上受支持,您可以引导用户登录(例如,在他们按下漂亮的按钮之后)。
import { signInWithApple, SignInWithAppleAuthorization } from "nativescript-apple-sign-in";
signInWithApple(
{
// by default you don't get these details, but if you provide these scopes you will (and the user will get to choose which ones are allowed)
scopes: ["EMAIL", "FULLNAME"]
})
.then((result: SignInWithAppleAuthorization) => {
console.log("Signed in, credential: " + result.credential);
console.log("Signed in, familyName: " + result.credential.fullName.familyName);
// you can remember the user to check the sign in state later (see 'getSignInWithAppleState' below)
this.user = result.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));