V4 Tap iOS SDK-Tap 登录集成指南

⚠️ 注意 iOS SDK 要求 Xcode 版本最低为 15.3
本篇集成文档演示的是 V4 版本的 TapSDK 版本为 4.3.10

原文请点击跳转

一、 创建项目

![](https://img-blog.csdnimg.cn/img_convert/23f2d4bf536c1362db01c6ac7a43d6ea.png
在这里插入图片描述

二、导入依赖

打开终端使用 pod 方式远程依赖;

1、进入项目目录下

cd YouProjectPath

2、生成 Profile 文件

pod init

3、在 Profile 文件中添加需要引入的依赖:

pod 'TapTapLoginSDK', '~> 4.3.10'
pod 'TapTapCoreSDK', '~> 4.3.10'

添加后文件内容如下:

4、 保存文件后执行安装的命令:

pod install

5 安装完成后,双击项目目录中的 **项目名.xcworkspace **文件,打开项目。

三、项目配置

1、 配置编译选项
  • 在 Build Setting 中的 Other Link Flag 中添加 -ObjC 和 -Wl -ld_classic。
  • 在 Build Setting 中的 Always Embed Swift Standard Libraries 设置为 YES,即始终引入 Swift 标准库,避免 App 启动时报错「无法找到 Swift 标准库之类」。如果项目中找不到,可以建立一个空 Swift 文件,Xcode 会自动建立桥接关系。
  • 在 Build Setting 中的 Swift Compiler - Language/Swift Language Version 选择 Swift 5。

  • 将工程 Pods 目录下 TapTapLoginSDK/Frameworks/TapTapLoginResource.bundle 资源文件导入工程中

点击 + 号将 Pods 文件夹中的 TapTapLoginResource.bundle 文件夹添加即可。

2、工程配置

1.打开 info.plist,添加如下配置(请替换 clientID 为你在控制台获取的 Client ID):

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLName</key>
        <string>taptap</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <!-- 这里注意下,中括号需要去掉,最终是 Client ID 前拼接上 `tt` 的形式,例如:ttFwFdCxxxxxxxQDQwQN -->
            <string>tt[clientID]</string>
        </array>
    </dict>
</array>

<key>LSApplicationQueriesSchemes</key>
<array>
  <string>tapiosdk</string>
  <string>tapsdk</string>
  <string>taptap</string>
</array>
  1. 配置 openUrl
  • 如果项目中有 SceneDelegate.swift,请先删除,然后请添加如下代码到 AppDelegate.swift 文件:
import TapTapLoginSDK

func application(_ app: UIApplication, open url: URL) -> Bool {
    return TapTapLogin.open(url: url)
}
    
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    return TapTapLogin.open(url: url)
}
    
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
    return TapTapLogin.open(url: url)
}
  • 删除 info.plist 里面的 Application Scene Manifest

  • 删除 AppDelegate.swift 文件中的两个管理 Scenedelegate 生命周期代理方法

func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
    
}
    
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
    
}
  • 在 AppDelegate.swift 中添加 UIWindow

四、功能接口

示例代码见 ViewController.swift 文件中内容:

import UIKit
import TapTapCoreSDK

import TapTapLoginSDK


class ViewController: UIViewController {

    var scopes: [Scope] = [Scope.publicProfile]

    // 定义两个按钮
    let button1 = UIButton(type: .system)
    let button2 = UIButton(type: .system)

    override func viewDidLoad() {
        super.viewDidLoad()

        setupButtons()
    }

    func setupButtons() {
        // 设置按钮1
        button1.setTitle("初始化", for: .normal)
        button1.frame = CGRect(x: 50, y: 100, width: 200, height: 50)
        button1.addTarget(self, action: #selector(button1Clicked), for: .touchUpInside)
        view.addSubview(button1)

        // 设置按钮2
        button2.setTitle("登录", for: .normal)
        button2.frame = CGRect(x: 50, y: 200, width: 200, height: 50)
        button2.addTarget(self, action: #selector(button2Clicked), for: .touchUpInside)
        view.addSubview(button2)
    }

    // 按钮1点击事件,打印1
    @objc func button1Clicked() {
        // 核心配置项
        let options = TapTapSdkOptions()
        options.clientId = "y2a********vh47m"
        options.clientToken = "XknZNP*********NzsiPgN0tp******PDHM"
        options.region = .CN
        options.enableLog = true
        options.preferredLanguage = TapLanguageType.auto

        TapTapSDK.initWith(options)
    }

    // 按钮2点击事件,打印1
    @objc func button2Clicked() {
        TapTapLogin.login(with: scopes) { [weak self] account, error, isCancel in
                                         guard let self = self else { return }

                                         if isCancel {
                                             self.handleLoginCancelled()
                                             return
                                         }

                                         if let error = error {
                                             self.handleLoginError(error)
                                             return
                                         }

                                         if let account = account {
                                             self.handleSuccessfulLogin(account: account)
                                         } else {
                                             self.handleUnknownError()
                                         }
                                        }
    }

    func handleSuccessfulLogin(account: TapTapLoginSDK.TapTapAccount) {
        print("登录成功")
    }

    func handleLoginError(_ error: Error) {
        print("登录失败")
    }

    func handleLoginCancelled() {
        print("用户取消了登录")
        // 处理用户取消登录的情况
    }

    func handleUnknownError() {
        print("登录过程中发生未知错误")
        // 处理未知错误情况
    }
}

五、编译打包

六、遇到的问题:

1、如果编译中报错:
Multiple commands produce '/Users/ggghhh/Library/Developer/Xcode/DerivedData/TestV4-cslrpkjkfditukenwptbwubpssmc/Build/Products/Debug-iphoneos/TestV4.app/TapTapLoginResource.bundle'
表示 TapTapLoginResource.bundle 重复引入了,可以将如下图位置中的 TapTapLoginResource.bundle 删除;

2、如果报错:

Sandbox: rsync.samba(41256) deny(1) file-write-create

可以将 User Script Sandboxing 设置为 NO

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值