概述
Envoy iOS SDK旨在为iOS应用程序提供快速的内容分享解决方案。
授权和Mixpanel使用:目前在这些方面,ios-sdk有所过时
快速入门指南
1. 安装Envoy SDK
您可以使用CocoaPods来安装Envoy iOS SDK - Swift库。您需要项目令牌来初始化您的库。您可以从账户设置中获取项目令牌。
CocoaPods安装
- 如果您这是第一次使用 CocoaPods,请使用以下命令安装 CocoaPods:
gem install cocoapods
。否则,继续进行到第 3 步。 - 运行
pod setup
命令以创建本地的 CocoaPods 规范镜像。 - 在您的 Xcode 项目目录下创建一个 Podfile 文件。通过在终端运行
pod init
命令来创建,编辑生成的 Podfile 文件,并添加以下行:pod 'EnvoySDK'
。 - 在您的 Xcode 项目目录下运行
pod install
命令。CocoaPods 应该下载并安装 EnvoySDK 库,并创建一个新的 Xcode 工作空间。在 Xcode 中打开此工作空间或使用终端中的open *.xcworkspace
命令。
2. 初始化 EnvoySDK
要初始化库,请将 import EnvoySDK
添加到 AppDelegate
中,并在 application:didFinishLaunchingWithOptions: 中调用 initialize()
。
import EnvoySDK
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
...
Envoy.initialize()
...
}
CreateLinkRequest
3. 配置 您需要使用您想要分享的内容来配置 CreateLinkRequest
。请求相当灵活,既有必需值也有可选值。
struct CreateLinkRequest {
let userId: String
let contentConfig: ContentConfig
let linkPreview: LinkPreview?
let autoplay: Bool?
let extra: [String : String]?
}
struct ContentConfig {
let contentType: String
let contentName: String
let contentDescription: String
let contentId: String
let common: Common
}
struct Common {
let media: Media
}
struct Media {
let source: String
let poster: String
}
struct LinkPreview {
let title: String
let linkPreviewDescription: String
let image: String
}
4. 添加礼物按钮(可选)
SDK 提供了添加带有 SDK 设计的礼物按钮的功能,以便快速实现。
let button = envoySDK.giftButton(request: request)
buttin.addTarget(self, action: #selector(giftAction), for: .touchUpInside)
containerView.addSubview(button)
5. 显示分享界面
要展示共享屏幕,您需要使用 apiKey
初始化 Envoy
实例。您可以从 账户设置 中获取项目令牌。在点击分享按钮后,需要调用以下方法之一。
func presentShareGift(from viewController: UIViewController, request: CreateLinkRequest)
func pushShareGift(in navigationController: UINavigationController, request: CreateLinkRequest)
import EnvoySDK
class ViewController: UIViewController {
...
func giftAction() {
envoySDK.presentShareGift(from: self, request: request)
}
...
}