ApesterObjcBridging 3.3.17

ApesterObjcBridging 3.3.17

michael kroitoro 维护。



  • Hasan Sa 和 ArkadiYoskovitz

ApesterKit

Platforms License

Swift Package Manager Carthage compatible CocoaPods compatible

ApesterKit 提供了一个轻量级框架,该框架在 webView 中加载 Apester Unit

要求

  • iOS 11.0+
  • Xcode 10.2+

集成

更新您的 app 的 Info.plist 文件以添加 Apester AdMob 应用 ID。.(联系 Apester 以获取)

For testing please use this key:

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

Apester Strip View

一个包含媒体出版商的 Apester Units 的频道的 Carousel 组件。这些组件是使用 Apester 平台 构建的,Carousel 组件的样式可以配置并显示在任何位置。按照我们的指南逐步设置

实现

1 - 声明类型为 APEStripView 的变量
## Swift
private var stripView: APEStripView!
## Objective C
@property (nonatomic, strong) APEStripView *stripView;
2 - 初始化条带样式的配置 APEStripStyle。配置条带视图样式,即形状、大小、内边距、阴影、标题头部等...
## 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 - 初始化条带配置 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 - 使用参数值初始化条带视图实例
## Swift
self.stripView = APEStripView(configuration: config)
## Objective C
self.stripView = [[APEStripView alloc] initWithConfiguration:config];
5 - 条带在容器视图中
5.1 - 显示(带有容器视图控制器用于导航目的)。
## Swift
stripView?.display(in: self.containerView, containerViewController: self)
## Objective C
[self.stripView displayIn:self.containerView containerViewController:self];
5.2 - 隐藏渠道条带视图。
## Swift
self.stripView.hide()
## Objective C
[self.stripView hide];
6 - 实现 APEStripViewDelegate 以观察条带视图的成功、失败或高度更新。

Apester Unit View

出版商 Apester 媒体的 Unit 或播放列表组件。这些组件是使用 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 以观察单元视图的成功、失败或高度更新。

APEViewService

一个提供预缓存 Apester Units 的服务,可以是 APEStripViewAPEUnitView .

APEStripView

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

APEUnitView

1 - 预加载多个具有 unit 配置 的单元视图
## 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中的didReceiveEvent,以便在事件被调用时观察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

要构建ApesterKit,需要CocoaPods 1.1.0+。

要将ApesterKit集成到您的Xcode项目中使用CocoaPods,请在您的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仓库
$ git init
  • 通过运行以下命令将ApesterKit添加为git 子模块
$ git submodule add https://github.com/Qmerce/ios-sdk.git
$ git submodule update --init --recursive
  • 打开新的ApesterKit文件夹,并将ApesterKit.xcodeproj拖放到应用程序的Xcode项目中的项目导航器中。

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

  • 在项目导航器中选择ApesterKit.xcodeproj,并验证部署目标是否与您的应用程序目标一致。
  • 接下来,在项目导航器中选择您的应用程序项目(蓝色项目图标),导航到目标配置窗口,在侧边栏中的“目标”部分下选择应用程序目标。
  • 在此窗口顶部的标签栏中,打开“通用”面板。
  • 在“嵌入式二进制”部分下单击“+”按钮。
  • 您将看到两个不同的ApesterKit.xcodeproj文件夹,每个文件夹中都有两个不同的版本的ApesterKit.framework嵌套在“Products”文件夹中。

您可以选择任何Products文件夹。

  • 选择ApesterKit.framework

  • 这样就完成了!

ApesterKit.framework将自动添加为目标依赖项,链接框架并嵌入框架到一个复制文件构建阶段,这就是您在模拟器和设备上构建所需的所有内容。

克隆项目并运行ApesterKitDemo应用程序

1 - clone it `git clone [email protected]:Qmerce/ios-sdk.git`.
2 -  run `carthage update`.
3 - select ApesterKitDemo Target.
4 - run the App and enjoy.

许可

ApesterKit使用MIT许可证发布。有关详细信息,请参阅LICENSE