Linksquared 是一个强大的 SDK,它使您可以在 iOS 应用程序内部进行深度链接和通用链接。这份文档作为指南,可帮助您在项目中无缝集成和利用 Linksquared。
Linksquared 可作为 Swift Package Manager (SPM) 包使用。您可以按照以下步骤将它添加到项目中
- 在 Xcode 中,转到文件 -> Swift Packages -> 添加包依赖。
- 输入仓库 URL:
https://github.com/your-repository/linksquared.git
。 - 选择符合您项目要求的版本范围。
- 点击下一步,然后完成。
要使用 COCOCAPODS 集成 SDK,请将 pod 添加到 Podfile 中
pod 'linksquared'
为了在您的应用程序中配置 Linksquared SDK,请按照以下步骤操作
- 在 Swift 文件中导入 Linksquared 模块
import Linksquared
- 使用您的 API 密钥初始化 SDK(通常在 AppDelegate 中)
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) {
Linksquared.configure(APIKey: "your-api-key", delegate: yourDelegate)
# Optionally, you can adjust the debug level for logging:
Linksquared.setDebug(level: .info)
... Your other code ...
}
如果您的应用程序使用场景代理,您需要将相关调用转发到 Linksquared。
// Handle open URL contexts
@available(iOS 13.0, *)
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
Linksquared.handleSceneDelegate(openURLContexts: URLContexts)
}
// Handle continue user activity
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
Linksquared.handleSceneDelegate(continue: userActivity)
}
// Handle scene delegate options
@available(iOS 13.0, *)
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
Linksquared.handleSceneDelegate(options: connectionOptions)
}
如果您的应用程序不使用场景代理,您应该将相关调用从应用程序代理转发到 Linksquared
// Handle universal link continuation
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
return Linksquared.handleAppDelegate(continue: userActivity, restorationHandler: restorationHandler)
}
// Handle URI opening
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
return Linksquared.handleAppDelegate(open: url, options: options)
}
配置完毕后,您可以利用 Linksquared 提供的多种功能。
您可以通过遵守 LinksquaredDelegate 协议来接收深度链接事件。以下是如何实现的示例
class YourViewController: UIViewController, LinksquaredDelegate {
override func viewDidLoad() {
super.viewDidLoad()
Linksquared.delegate = self
}
// Implement the delegate method
func linksquaredReceivedPayloadFromDeeplink(payload: [String: Any]) {
// Handle the received payload here
}
}
Linksquared.generateLink(title: "Link Title", subtitle: "Link Subtitle", imageURL: "imageURL", data: ["key": "value"]) { url in
// Handle generated URL
}
有关进一步的帮助和详细文档,请参考 https://linksquared.io/docs 上可用的 Linksquared 文档。
有关技术支持和咨询,请联系我们的支持团队 [email protected]。
感谢您选择 Linksquared!我们期待看到您用我们的 SDK 创作出的成果。
版权所有 linksquared。