title: 快速入门

你可以通过邮箱登录的例子来了解身份认证的基本用法。

环境准备

  • 支持 Xcode 7.0 及以上版本
  • 支持 iOS 7.0 及以上版本

1. 创建应用

首先,你需要在控制面板中创建应用。

2. 安装 SDK

SDK 的安装方式有两种,你可以任选其一:

  • 使用 CocoaPods

要将 Wilddog SDK 导入到你的工程中,推荐使用 CocoaPods,如果没用过 CocoaPods,请先访问 CocoaPods getting started

打开工程目录,新建一个 Podfile 文件

  1. $ cd your-project-directory
  2. $ pod init
  3. $ open -a Xcode Podfile # opens your Podfile in XCode

然后在 Podfile 文件中添加以下语句

  1. pod 'Wilddog/Auth'

最后安装 SDK

  1. $ pod install
  2. $ open your-project.xcworkspace


  • 手动集成
  1. 下载 Auth SDK 点此下载
  2. 下载 Core SDK 点此下载
  3. 把 WilddogAuth.framework 和 WilddogCore.framework 拖到工程目录中。
  4. 选中 Copy items if needed 、Create Groups,点击 Finish。
  5. 点击工程文件 -> TARGETS -> Build Settings,在 Other Linker Flags 中添加 -ObjC。

3. 创建 Auth 实例

使用 Wilddog Auth SDK 之前,需要先创建实例:

1.引入头文件

Objective-C Swift
objectivec @import Wilddog;
swift import Wilddog

2.初始化

Objective-C Swift
objectivec //初始化 WDGApp WDGOptions *options = [[WDGOptions alloc] initWithSyncURL:@"https://your-wilddog-appid.wilddogio.com"]; [WDGApp configureWithOptions:options]; WDGAuth *auth = [WDGAuth auth];
swift //初始化 WDGApp let options = WDGOptions.init(syncURL: "https://your-wilddog-appid.wilddogio.com") WDGApp.configure(with: options) let auth = WDGAuth.auth()

4. 使用邮箱认证

1.开启邮箱登录

在 控制面板—身份认证—登录方式 中开启邮箱登录功能:

title: 快速入门 - 图1

2.创建新用户

Objective-C Swift
objectivec //创建一个基于密码的帐户,创建成功后会自动登录 [auth createUserWithEmail:@"user@example.com" password:@"password" completion:^(WDGUser * _Nullable user, NSError * _Nullable error) { //... }];
swift //创建一个基于密码的帐户,创建成功后会自动登录 auth?.createUser(withEmail: "user@example.com", password:"password", completion: { (user, error) in //... })

3.邮箱密码登录

signInWithEmail 方法用于已创建的用户登录:

Objective-C Swift
objectivec [auth signInWithEmail:email password:password completion:^(WDGUser *user, NSError *error) { // ... }];
swift auth?.signIn(withEmail: email, password: password) { (user, error) in // ... }

5. 退出登录

signOut 方法用于退出当前登录用户:

Objective-C Swift
objectivec NSError *error; [[WDGAuth auth] signOut:&error]; if (!error) { // 退出登录成功 }
swift try! WDGAuth.auth()!.signOut()

Auth 更多使用方式,请参考 完整指南API 文档