nativeScript-apple-sign-in-enduco
使用 Apple 登录
npm i --save nativeScript-apple-sign-in-enduco

使用 Apple 登录,适用于 NativeScript

Build Status NPM version Downloads Twitter Follow

要求

  • 访问 苹果开发者网站 并创建一个新的应用程序标识符,启用“使用 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));