GobiSDK 1.0.0

GobiSDK 1.0.0

Gobitech维护。



GobiSDK 1.0.0

  • Gobitech

GobiSDK

Version License Platform

安装

GobiSDK可通过CocoaPods获得。要安装它,只需将以下行添加到Podfile中

pod 'GobiSDK'

获取您的访问密钥

您可以从Gobitech AS通过电子邮件获取它们,地址为[email protected]

集成到应用程序中

1. 导入Gobi SDK

import GobiSDK

2. 在视图控制器中初始化 Gobi 示例,例如在 viewDidLoad()

override func viewDidLoad() {
    super.viewDidLoad()
    Gobi.with("ZDY5OGI0YZQ3MJG0MWE3ZDA0YWEXZDLK", delegate: self)
}

注意委托实例应遵循 GobiDelegate 协议。

委托参数是可选的,因此如果不需要任何回调,初始化可能如下

override func viewDidLoad() {
    super.viewDidLoad()
    Gobi.with("ZDY5OGI0YZQ3MJG0MWE3ZDA0YWEXZDLK")
}

3. 保存你的故事键

struct Stories {
    static var gobiTeamStoryId = "YZY5MJVKOWYWN2NIOTNIYTLIN2MXODGYOWZKNDU3YWZLNGM4MGUYMJNMMJIWNTG4"
}

使用方法

1. 获取故事信息

func loadStory() {
    Gobi.getStoryData(for: Stories.gobiTeamStoryId)
}

当接收到故事信息时,将调用委托方法 func didReceiveStory(_ story: GobiStory)

2. 显示一个故事

使用方法 Gobi.showStory(with id: String, from vc: UIViewController) 来显示指定 ID 的故事 id 的新图片和视频,并在 vc 上显示。

    Gobi.showStory(with: Stories.gobiTeamStoryId, from: self)

3. 回退一个故事

使用方法 Gobi.rewindStory(with id: String, from vc: UIViewController) 来显示指定 ID 的故事 id 所有的图片和视频,并在 vc 上显示。

    Gobi.rewindStory(with: Stories.gobiTeamStoryId, from: self)

4. 检查故事是否有新图像和视频以决定播放或回放

func showStory(_ story: GobiStory) {
    if story.unreadCount > 0 {
        Gobi.showStory(with: Stories.gobiTeamStoryId, from: self)
    } else {
        Gobi.rewindStory(with: Stories.gobiTeamStoryId, from: self)
    }
}

5. 将媒体上传到故事

GobiSDK 支持向一个或多个故事上传媒体。

使用 public static func addMedia(to storyID: String, from vc: UIViewController) 发布一个故事

    Gobi.addMedia(to: storyKey, from: self)

或者使用 public static func addMedia(to storyIDs: [String], from vc: UIViewController) 允许用户从列表中选择要将媒体添加到哪些故事中。

    Gobi.addMedia(to: [storyKey], from: self)

调用这些方法时,GobiSDK 将打开相机,让用户拍照或拍摄视频,然后添加贴纸、文字或绘画,再上传媒体。

6. GobiDelegate

public protocol GobiDelegate {

    public func didReceiveStory(_ story: GobiStory)

    public func didFailWith(_ error: GobiError)

    public func didFinishShowingMedia()

    public func didFinishAddingMedia(success: Bool)

    public func didStartUploadingMedia(with id: String)

    public func didFailUploadingMedia(with id: String)

    public func didFinishUploadingMedia(with id: String)

}

public func didReceiveStory(_ story: GobiStory)

当调用 Gobi.getStoryData(for: Stories.gobiTeamStoryId) 后从 Gobi 中检索到故事时,将调用此方法。

public func didFailWith(_ error: GobiError)

当请求的任何操作无法完成时,将调用此方法。 GobiError 是一个枚举。

public enum GobiError : Error, ErrorStringConvertible {

    case invalidCustomerId

    case invalidStoryKey

    case requestFailed(String)

    case failedToLoadStory

    case failedToLoadMedia

    case noNewImagesInStory

    case noImagesInStory

    public var errorDescription: String { get }
}

公共函数 didFinishShowingMedia()

当 GobiSDK 播放完故事并关闭控制器时调用此方法。如果 UI 显示 GobiStory,可以在该位置调用 getStoryData 来加载更新信息,如缩略图、未读数量等。

公共函数 didFinishAddingMedia(success: Bool)

当 GobiSDK 成功上传媒体或因某些原因失败时调用此方法。

公共函数 didStartUploadingMedia(with id: String)

当 GobiSDK 开始上传媒体到故事时调用此方法。id 是媒体的本地唯一标识符。SDK 支持在后台上传媒体,因此如果上传失败,该方法可能被多次调用。

公共函数 didFailUploadingMedia(with id: String)

当 GobiSDK 失败上传给定 id 的媒体时调用此方法。SDK 将稍后重试上传此资源。

公共函数 didFinishUploadingMedia(with id: String)

当 GobiSDK 成功上传给定 id 的媒体时调用此方法。

使用说明

1. 要隐藏视频播放器的状态栏,请确保在Info.plist文件中将View controller-based status bar appearance设置为YES。

2. 确保Info.plist包含App Transport Security Settings和Allow Arbitrary Loads设置为YES。

作者

Gobitech

许可证

GobiSDK遵循Apache 2.0许可证。有关更多信息,请参阅LICENSE文件。