ApesterKit

Platforms License

Swift Package Manager Carthage compatible CocoaPods compatible

ApesterKit 提供了一个轻量级框架,用于在 webView 中加载 Apester 单元

要求

集成

更新您应用程序的 Info.plist 文件,添加 Apester AdMob 应用 ID。(联系 Apester 获取此 ID)。

For testing please use this key:

<key>GADApplicationIdentifier</key>
<string>ca-app-pub-3940256099942544~1458002511</string>

Apester Strip 视图

一个用于频道的轮播组件,其中包含媒体发布者的 Apester 单元。 这些单元使用 Apester 平台构建。轮播组件的设计可以配置并显示在任何位置。 请按照我们的分步指南进行设置。

实现

1 - 声明 APEStripView 类型的变量
## Swift
private var stripView: APEStripView!
## Objective C
@property (nonatomic, strong) APEStripView *stripView;
2 - 初始化一个 strip 样式配置 APEStripStyle。 配置 strip 视图的样式,例如形状、大小、内边距、阴影、标题等...
## Swift
let header = APEStripHeader(text: "Title", size: 25.0, family: nil, weight: 400, color: .darkText)
let style  = APEStripStyle(shape: .roundSquare, size: .medium, 
                         padding: UIEdgeInsets(top: 5.0, left: 0, bottom: 0, right: 0),
                         shadow: false, textColor: nil, background: nil, header: header)
## Objective C
APEStripHeader *header =  [[APEStripHeader alloc] initWithText:@"Title" size:25.0 family:nil weight:400 color:[UIColor purpleColor]];
APEStripStyle *style = [[APEStripStyle alloc] initWithShape:APEStripShapeRoundSquare
                                                       size:APEStripSizeMedium
                                                    padding:UIEdgeInsetsMake(10.0, 0, 0, 0)
                                                     shadow:NO  
                                                     textColor:nil
                                                     background:[UIColor whiteColor]
                                                     header:header];
3 - 初始化一个 strip 配置 APEStripConfiguration。 设置频道令牌、样式和捆绑参数...
## Swift
let configuration = try? APEStripConfiguration(channelToken: channelToken,
                                               style: style,
                                               bundle: Bundle.main)
## Objective C
NSError *error = nil;
APEStripConfiguration *config = [[APEStripConfiguration alloc] initWithChannelToken:channelToken
                                                               style:style
                                                               bundle:[NSBundle mainBundle]
                                                               error:&error];
4 - 使用参数值初始化 strip 视图实例。
## Swift
self.stripView = APEStripView(configuration: config)
## Objective C
self.stripView = [[APEStripView alloc] initWithConfiguration:config];
5 - 将频道 strip 放在容器视图中
5.1 - 显示(使用容器视图控制器进行导航)。
## Swift
stripView?.display(in: self.containerView, containerViewController: self)
## Objective C
[self.stripView displayIn:self.containerView containerViewController:self];
5.2 - 隐藏频道 strip 视图。
## Swift
self.stripView.hide()
## Objective C
[self.stripView hide];
6 - 实现 APEStripViewDelegate 以在成功、失败或高度更新时观察 stripView 的更新。

Apester 单元视图

一个用于发布者 Apester 媒体的单元或播放列表组件。 这些单元使用 Apester 平台构建。

1 - 声明 APEUnitView 类型的变量
## Swift
private var unitView: APEUnitView!
## Objective C
@property (nonatomic, strong) APEUnitView *unitView;
2 - 初始化一个单元参数 APEUnitParams。 设置媒体 ID 或用于播放列表的频道令牌。
## Swift

let unitParams = .unit(mediaId: mediaId)
// OR
let playlistParams = .playlist(tags: tags,
                               channelToken: channelToken,
                               context: isContext,
                               fallback: isFallback)
3 - 初始化一个单元配置 APEUnitConfiguration。 设置单元参数和捆绑包
## Swift
let unitConfig = APEUnitConfiguration(unitParams: unitParams, bundle: Bundle.main)
// OR
let playlistConfig = APEUnitConfiguration(unitParams: playlistParams, bundle: Bundle.main)
## Objective C
APEUnitConfiguration *unitConfig = [[APEUnitConfiguration alloc] initWithMediaId:meidaId bundle: NSBundle.mainBundle];
// OR
APEUnitConfiguration *playlistConfig = [[APEUnitConfiguration alloc] initWithTags: mediaIds
                                                                     channelToken: channelToken
                                                                     context: isContext 
                                                                     fallback: isFallback
                                                                     bundle: NSBundle.mainBundle
                                                                     gdprString: gdprString
                                                                     baseUrl: baseUrl];

可选设置

## Swift
configuration.setFullscreen(true)
## Objective C
[ configuration setFullscreen: true ];
4 - 使用参数值初始化单元视图实例。
## Swift
self.unitView = APEUnitView(configuration: configuration)
## Objective C
self.unitView = [[APEUnitView alloc] initWithConfiguration:unitConfig];
// OR
self.unitView = [[APEUnitView alloc] initWithConfiguration:playlistConfig];
5 - 将单元视图放在容器视图中
5.1 - 显示(使用容器视图控制器进行导航)。
## Swift
unitView?.display(in: self.containerView, containerViewController: self)
## Objective C
[self.unitView displayIn:self.containerView containerViewController:self];
5.2 - 隐藏单元视图。
## Swift
self.unitView.hide()
## Objective C
[self.unitView hide];
5.3 - 重新加载单元视图。
## Swift
self.unitView.reload()
## Objective C
[self.unitView reload];
6 - 实现 APEUnitViewDelegate 以在成功、失败或高度更新时观察 stripView 的更新。

APEViewService

一项服务,用于预缓存 Apester 单元,可以是 APEStripViewAPEUnitView

APEStripView

1 - 使用 strip configurations 预加载多个 strip 视图
## Swift
APEViewService.shared.preloadStripViews(with: configurations)
## Objective C
[APEViewService.shared preloadStripViewsWith: configurations];
2 - 卸载 strip 视图,以便可以使用给定的 channelTokens 从缓存中删除(如果存在)
## Swift
APEViewService.shared.unloadStripViews(with: channelTokens)
## Objective C
[APEViewService.shared unloadStripViewsWith: channelTokens];
3 - 获取给定 channelToken 的缓存 strip 视图(如果存在)。
## Swift
APEViewService.shared.stripView(for: channelToken)
## Objective C
[APEViewService.shared stripViewFor: channelToken];

APEUnitView

1 - 使用 unit configurations 预加载多个单元视图
## Swift
APEViewService.shared.preloadUnitViews(with: configurations)
## Objective C
[APEViewService.shared preloadUnitViewsWith: configurations];
2 - 卸载单元视图,以便可以使用给定的 unitIds 从缓存中删除(如果存在)
## Swift
APEViewService.shared.unloadUnitViews(with: unitIds)
## Objective C
[APEViewService.shared unloadUnitViewsWith: unitIds];
3 - 获取给定 unitId 的缓存单元视图(如果存在)。
## Swift
APEViewService.shared.unitView(for: unitId)
## Objective C
[APEViewService.shared unitViewFor: unitId];

事件订阅

使用以下 API 设置事件侦听器。

## Swift
apesterUnitView.subscribe(events: ["apester_interaction_loaded", "click_next"]) // example events
## Objective C
NSArray *events = @[@"apester_interaction_loaded"];
[_apesterUnitView subscribeWithEvents:(NSArray<NSString *> * _Nonnull)events];
然后实现 APEStripViewDelegate - didReciveEvent 以观察调用事件时 unitView 的更新。

要订阅的示例事件:(要获取更多事件信息,请联系 Apester 团队)

事件名称 含义
click_next 点击了“下一步”
picked_answer 选择了答案
unit_started 首次参与
apester_interaction_loaded 单元已加载
fullscreen_off 单元全屏已关闭

重新开始故事

## Swift
apesterUnitView.restart()
## Objective C
[_apesterUnitView restart];

处理全屏故事

最佳实践

  1. 预加载单元,以便它们可以快速打开
  2. 当宿主活动暂停/恢复时,将其告知单元。
  3. 设置一个“关闭全屏事件”,以便该活动将在单击时自行关闭。

例子

启动时

## Swift
configuration.setFullscreen(true)
APEViewService.shared.preloadStripViews(with: configurations)

在宿主活动中

apesterUnitView.subscribe(events: ["fullscreen_off"]) // add more events as needed
apesterUnitView.delegate = self

在 ApeUnitViewDelegate 上

func unitView(_ unitView: APEUnitView, didReciveEvent name: String, message: String) {
    if name == "fullscreen_off" {
        finish();
    }
}

在视图控制器恢复或暂停功能内部

if #available(iOS 13.0, *) {
    NotificationCenter.default.addObserver(self, selector: #selector(willResignActive), name: UIScene.willDeactivateNotification, object: nil)
    NotificationCenter.default.addObserver(self, selector: #selector(willBackActive), name: UIScene.willEnterForegroundNotification, object: nil)
} else {
    NotificationCenter.default.addObserver(self, selector: #selector(willResignActive), name: UIApplication.willResignActiveNotification, object: nil)
    NotificationCenter.default.addObserver(self, selector: #selector(willBackActive), name: UIApplication.willEnterForegroundNotification, object: nil)
}

@objc func willResignActive(_ notification: Notification) {
    apesterUnitView.stop()
}

@objc func willBackActive(_ notification: Notification) {
    apesterUnitView.resume()
}

override func viewDidDisappear(_ animated: Bool) {
    apesterUnitView.stop()
}

override func viewDidAppear(_ animated: Bool) {
    apesterUnitView.resume()
}

安装

Swift 包管理器

Swift 包管理器 自动化了 Swift 代码的分发。 要将 ApesterKit 与 SPM 一起使用,请将依赖项添加到您的 Package.swift 文件中

let package = Package(
                      dependencies: [
                        .package(url: "https://github.com/Qmerce/ios-sdk.git", from: "2.0.0")
                      ]
)

CocoaPods

CocoaPods 是 Cocoa 项目的依赖管理器。 您可以使用以下命令安装它

$ gem install cocoapods

需要 CocoaPods 1.1.0+ 才能构建 ApesterKit。

要使用 CocoaPods 将 ApesterKit 集成到您的 Xcode 项目中,请在您的 Podfile 中指定它

platform :ios, '11.0'

use_frameworks!
pod 'ApesterKit'

然后,运行以下命令

$ pod install

Carthage

Carthage 是一个去中心化的依赖管理器,它可以自动将框架添加到您的 Cocoa 应用程序中。

您可以使用 Homebrew 安装 Carthage,方法是使用以下命令

$ brew update
$ brew install carthage

要使用 Carthage 将 ApesterKit 集成到您的 Xcode 项目中,请在您的 Cartfile 中指定它

github 'Qmerce/ios-sdk'

然后,运行以下命令

$ carthage update --platform iOS --use-submodules

手动

如果您不想使用上述任何依赖管理器,您可以手动将 ApesterKit 集成到您的项目中。

Git 子模块

$ git init
$ git submodule add https://github.com/Qmerce/ios-sdk.git
$ git submodule update --init --recursive

它应该嵌套在您的应用程序的蓝色项目图标下。 它是在所有其他 Xcode 组之上还是之下无关紧要。

您选择哪个 Products 文件夹并不重要。

ApesterKit.framework 会自动添加为目标依赖项、链接框架和嵌入式框架,在复制文件构建阶段中,这是在模拟器和设备上构建所需的一切。

克隆项目并运行 ApesterKitDemo App

1 - clone it `git clone git@github.com:Qmerce/ios-sdk.git`.
2 -  run `carthage update`.
3 - select ApesterKitDemo Target.
4 - run the App and enjoy.

许可

ApesterKit 在 MIT 许可下发布。 有关详细信息,请参见 LICENSE