Swift SDK 安装

Shayan Taslim更新

使用 Swift Package Manager 安装 Swift SDK,然后在应用启动时使用你的 UserJot Project ID 对其进行初始化。

系统要求

  • iOS 15.0+ 或 macOS 12.0+

  • Swift 6.1+

  • Xcode 16.3+

使用 Swift Package Manager 安装

在 Xcode 中

  1. 在 Xcode 中打开你的项目。

  2. 前往 文件 → 添加软件包依赖项。

  3. 输入此软件包 URL:

text
https://github.com/UserJot/userjot-ios
  1. 将 UserJot 软件包添加到你的应用目标。

在 Package.swift 中

Swift
dependencies: [
    .package(url: "https://github.com/UserJot/userjot-ios", from: "0.4.0")
]

查找你的 Project ID

在 UserJot 控制面板中前往 设置 → 登录,然后在 密钥部分复制 Project ID。

初始化 SDK

在应用启动时调用一次 UserJot.setup(projectId:):

SwiftUI

Swift
import SwiftUI
import UserJot

@main
struct MyApp: App {
    init() {
        UserJot.setup(projectId: "YOUR_PROJECT_ID")
    }

    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

UIKit

Swift
import UIKit
import UserJot

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
    ) -> Bool {
        UserJot.setup(projectId: "YOUR_PROJECT_ID")
        return true
    }
}

验证集成

setup 会立即返回,并在后台加载你的看板地址。任何 show 调用都会等待地址加载完成后再显示内容;如果设备在启动时处于离线状态,则会重试。

Swift
Button("Send Feedback") {
    UserJot.showFeedback()
}

出于相同原因,URL 辅助方法(feedbackURL(board:)、roadmapURL()、updatesURL())均为 async;如果无法加载地址,则会返回 nil。

macOS 权限配置

对于启用了沙盒的 macOS 应用,请在应用权限配置中启用出站网络访问:

xml
<key>com.apple.security.network.client</key>
<true/>

从 0.3 迁移

  • showChangelog() 现在是 showUpdates(),而 changelogURL() 现在是 updatesURL()(旧名称会发出弃用警告,并将在 1.0 中移除)。

  • feedbackURL(board:)、roadmapURL() 和 updatesURL() 现在都是 async。

  • UserJot 现在隔离在主 actor 上;请在后台任务中使用 await 调用。

  • 最低支持平台为 iOS 15 和 macOS 12。

后续步骤

这是否解答了您的问题?