Skip to content

指色IOS聚合SDK接入文档

该SDK已被废弃,请查看SeegSdk接入

版本记录

版本号修改时间修改内容支持
1.3.0.22021-02-01更新SDK支持
1.0.0.02021-01-11优化SDK支持
1.0.02020-10-29初版测试版

SDK接入

集成准备

将平台提供的SDK拖入工程,本SDK已支持IOS14,请将XCode版本升级到12以上

需要添加的系统库

  • libz.tbd

  • libsqlite3.tbd

  • Foundation.framework

  • UIKit.framework

  • JavaScriptCore.framework

  • WebKit.framework

  • CoreFoundation.framework

  • CoreTelephony.framework

  • Security.framework

  • SystemConfiguration.framework

  • AdSupport.framework

  • StoreKit.framework

  • MobileCoreServices.framework

  • MediaPlayer.framework

  • CoreMedia.framework

  • CoreLocation.framework

  • AVFoundation.framework

  • CoreMotion.framework

  • Accelerate.framework

  • libresolv.9.tbd

  • libc++.tbd

  • libbz2.tbd

  • libxml2.tbd

  • ImageIO.framework

  • QuartzCore.framework

  • libiconv.tbd

权限请求

    <key>SKAdNetworkItems</key>
    <array>
      <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>238da6jt44.skadnetwork</string>
      </dict>
      <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>22mmun2rn5.skadnetwork</string>
      </dict>
    </array>
  • 可选权限
    <key>NSUserTrackingUsageDescription</key>
    <string>请允许获取并使用您的IDFA</string>
    <key>NSCameraUsageDescription</key>
    <string>需要您的同意才能访问相机</string>
    <key>NSPhotoLibraryUsageDescription</key>
    <string>需要您的同意才能访问相册</string>
  • ios14需要自行获取idfa
  1. 导入 AppTrackingTransparency.framework 权限库
  2. 添加如下代码
    if (@available(iOS 14, *))
    {
        [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
            // 获取到权限后,依然使用老方法获取idfa
            if (status == ATTrackingManagerAuthorizationStatusAuthorized) {
                idfa = [[ASIdentifierManager sharedManager].advertisingIdentifier UUIDString];
            } else {
                ZSLog(@"请在设置-隐私-Tracking中允许App请求跟踪");
                idfa = @"";
            }
        }];
    } else {
        // Fallback on earlier versions
        if ([ASIdentifierManager.sharedManager isAdvertisingTrackingEnabled]) {
            idfa =  [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
        } else {
            idfa = @"";
        }
    }
}

注意事项

  • 添加WiFi信息

()[http://doc.talkingdata.com/archives/img/ios_1560310135255.jpg]

调用SDK

初始化

#import <ZSSdk/ZSConfig.h>
#import <ZSSdk/ZSSdk.h>

//...

    ZSConfig* config = [[ZSConfig alloc] init];
    config.appId = appId;
    config.channel = channel;  // IOS 平台无需求,则不需要处理
    config.idfa = @""; // 如果没有获取idfa,可以赋值为空字符串
    [ZSSdk initSdk: config application: application didFinishLaunchingWithOptions: launchOptions;];

JS游戏

添加JavaScript脚本

  • CocosCreator:scripts/zs-ccc.js

  例如cocos需在main.js中添加

    // ...
    if (isRuntime) {
        require('src/settings.js');
        require('src/cocos2d-runtime.js');
        if (CC_PHYSICS_BUILTIN || CC_PHYSICS_CANNON) {
            require('src/physics.js');
        }
        require('jsb-adapter/engine/index.js');
    } else {
        require('src/settings.js');
        require('src/cocos2d-jsb.js');
        if (CC_PHYSICS_BUILTIN || CC_PHYSICS_CANNON) {
            require('src/physics.js');
        }
        require('jsb-adapter/jsb-engine.js');
    }
    // 添加脚本文件
    require('scripts/zs-ccc.js');
    // ...
添加回调
#include "platform/CCApplication.h"
#include "cocos/scripting/js-bindings/jswrapper/SeApi.h"

// ...

    [ZSSdk onJSEval:^(NSString* jsCode){
        NSLog(@"jsCode=%@", jsCode);
        std::string str = [jsCode UTF8String];
        se::ScriptEngine::getInstance()->evalString(str.c_str());
    }];

调用开屏

#import <ZSSdk/ZUAdSlot.h>
#import <ZSSdk/ZUSplashAd.h>
#import <ZSSdk/ZUSplashAdListener.h>

// ...

    [ZSSdk onSdkLoadResult:^(){
        NSLog(@"setInitComplete");
        ZUAdSlot* adSlot = [[ZUAdSlot alloc] init];
        adSlot.adUnitId = @"";
        UIViewController *rootViewController =  [[UIApplication sharedApplication].delegate window].rootViewController;
        self.splashAd = [[ZUSplashAd alloc] initSlot: adSlot rootViewController: rootViewController];
        self.splashAd.delegate = self;
        [self.splashAd load];
    }];

// ...

- (void)onLoaded {
    [self.splashAd show];
}

ObjectC-API

DMP

ZDSdk.registerEvent

  1. 方法
+ (void)registerEvent:(NSString *) userId pf:(NSString *)pf isSuccess:(BOOL)isSuccess;
  1. 参数
属性类型默认值必填说明
pfstring登陆平台默认zhise
userIdstring用户id
isSuccessboolean是否成功必须成功一次
  1. 调用要求

必须调用,如果游戏不需要注册,可以第一次进入游戏时调用

ZDSdk.loginEvent

  1. 方法
+ (void)loginEvent:(NSString *) userId pf:(NSString *) pf isSuccess:(BOOL) isSuccess;
  1. 参数
属性类型默认值必填说明
pfstring登陆平台默认zhise
userIdstring用户id
isSuccessboolean是否成功必须成功一次
  1. 调用要求

必须上报,如果游戏不需要登录,可以在用户进入游戏时调用

ZDSdk.payEvent

  1. 方法
+ (void)payEvent:(NSString *) userId contentType:(NSString *)contentType contentName:(NSString *)contentName contentId:(NSString *)contentId contentNumber:(NSInteger)contentNumber paymentChannel:(NSString *)paymentChannel currency:(NSString *) currency isSuccess:(BOOL)isSuccess currencyAmount:(NSInteger)currencyAmount;
  1. 参数
属性类型默认值必填说明
userIdstring用户id
contentTypestring""
contentNamestring""
contentIdstring""
contentNumbernumber1
paymentChannelstringzs
currencystringRMB
isSuccessbooleantrue支付状态。
currencyAmountnumber1支付金额,单位分。
  1. 调用要求

必须上报,如果没有支付事件,请用其它事件(比如激励完成)代替

SAS

// 事件统计
+ (void) onEvent:(NSString *)eventId params:(NSDictionary *) params;
// 页面统计开始
+ (void) onPageStart:(NSString *) pageName;
// 页面统计结束
+ (void) onPageEnd:(NSString *) pageName;

横幅广告

  1. 示例

#import TestBannerAd

#import "ZUAdSlot.h"
#import "ZUBannerAd.h"
#import "ZUBannerAdListener.h"

@interface  TestBannerAd()<ZUBannerAdListener>

@property (nonatomic, strong) ZUBannerAd *ad;
@property (nonatomic, assign) BOOL isShow;

@end

@implementation TestBannerAd

-(instancetype) initAd:(NSInteger) adId adUnitId:(NSString *)adUnitId interval:(NSInteger)interval left:(NSInteger) left top:(NSInteger) top width:(NSInteger) width height:(NSInteger) height {
    ZUAdSlot *adSlot = [[ZUAdSlot alloc] init];
    adSlot.adUnitId = adUnitId;
    adSlot.intervals = interval;
    adSlot.width = width;
    adSlot.height = height;
    adSlot.left = left;
    adSlot.top = top;
    UIViewController *rootViewController = [UIApplication sharedApplication].windows[0].rootViewController;
    self.ad = [[ZUBannerAd alloc] initSlot: adSlot rootViewController:rootViewController];
    self.ad.delegate = self;
    return  self;
}

-(void) show {
    [self.ad load];
}

-(void) hide {
    [self.ad hide];
}

-(void) setLeft:(NSInteger) left {
    [self.ad setLeft:left];
}

-(void) setTop:(NSInteger) top {
    [self.ad setTop:top];
}

- (void)onLoadErrorCode:(NSInteger)errCode errMsg:(NSString *)errMsg {
}

- (void)onLoaded {
    [self.ad show];
}

- (void)onResizeWidth:(NSInteger)width height:(NSInteger)height {
}

- (void)onShow {
}

- (void)onShowErrorCode:(NSInteger)errCode errMsg:(NSString *)errMsg {
}

@end

插屏广告

  1. 示例

#import "TestInterstitialAd.h"

#import "ZUAdSlot.h"
#import "ZUInterstitialAd.h"
#import "ZUInterstitialAdListener.h"

@interface  TestInterstitialAd()<ZUInterstitialAdListener>

@property (nonatomic, strong) ZUInterstitialAd* ad;

@end

@implementation TestInterstitialAd

-(instancetype) initAd:(NSString *) adUnitId {
    ZUAdSlot *adSlot = [[ZUAdSlot alloc] init];
    adSlot.adUnitId = adUnitId;
    self.ad = [[ZUInterstitialAd alloc] initSlot: adSlot];
    self.ad.delegate = self;
    return  self;
}

-(void) load {
    [self.ad load];
}

-(void) show {
    UIViewController *rootViewController = [UIApplication sharedApplication].windows[0].rootViewController;
    [self.ad show: rootViewController];
}

- (void)onLoadErrorCode:(NSInteger)errCode errMsg:(NSString *)errMsg {
}

- (void)onLoaded {
}

- (void)onShow {
}

- (void)onShowErrorCode:(NSInteger)errCode errMsg:(NSString *)errMsg {
}

- (void)onClose:(BOOL)complete {
}


@end

激励广告

  1. 示例
#import "TestRewardedVideoAd.h"

#import "ZUAdSlot.h"
#import "ZURewardedVideoAd.h"
#import "ZURewardedVideoAdListener.h"

@interface  TestRewardedVideoAd()<ZURewardedVideoAdListener>

@property (nonatomic, strong) ZURewardedVideoAd* ad;

@end

@implementation TestRewardedVideoAd

-(instancetype) initAd:(NSString *)adUnitId {
    ZUAdSlot *adSlot = [[ZUAdSlot alloc] init];
    adSlot.adUnitId = adUnitId;
    self.ad = [[ZURewardedVideoAd alloc] initSlot: adSlot];
    self.ad.delegate = self;
    return  self;
}

-(void) load {
    [self.ad load];
}

-(void) show {
    UIViewController *rootViewController = [UIApplication sharedApplication].windows[0].rootViewController;
    [self.ad show: rootViewController];
}

- (void)onLoadErrorCode:(NSInteger)errCode errMsg:(NSString *)errMsg {
}

- (void)onLoaded {
}

- (void)onShow {
}

- (void)onShowErrorCode:(NSInteger)errCode errMsg:(NSString *)errMsg {
}

- (void)onClose:(BOOL)complete {
}

@end

信息流

  1. 示例
#import "TestNativeAd.h"

#import "ZUAdSlot.h"
#import "ZUNativeAd.h"
#import "ZUNativeAdListener.h"

@interface  TestNativeAd()<ZUNativeAdListener>

@property (nonatomic, strong) ZUNativeAd *ad;

@end

@implementation JSNativeAd

-(instancetype) initAd:(NSInteger) adId adUnitId:(NSString *)adUnitId left:(NSInteger) left top:(NSInteger) top width:(NSInteger) width height:(NSInteger) height {
    ZUAdSlot *adSlot = [[ZUAdSlot alloc] init];
    adSlot.adUnitId = adUnitId;
    adSlot.width = width;
    adSlot.height = height;
    adSlot.left = left;
    adSlot.top = top;
    UIViewController *rootViewController = [UIApplication sharedApplication].windows[0].rootViewController;
    self.ad = [[ZUNativeAd alloc] initSlot: adSlot rootViewController:rootViewController];
    self.ad.delegate = self;
    return  self;
}

-(void) show {
    [self.ad load];
}

-(void) hide {
    [self.ad hide];
}

-(void) setLeft:(NSInteger) left {
    [self.ad setLeft:left];
}

-(void) setTop:(NSInteger) top {
    [self.ad setTop:top];
}

- (void)onLoadErrorCode:(NSInteger)errCode errMsg:(NSString *)errMsg {
}

- (void)onLoaded {
    ZSMethod();
    [self.ad show];
}

- (void)onResizeWidth:(NSInteger)width height:(NSInteger)height {

}

- (void)onShow {

}

- (void)onShowErrorCode:(NSInteger)errCode errMsg:(NSString *)errMsg {

}

@end

JS-API

APP

zs.gameLoadResult

游戏加载完成

  1. 方法
zs.gameLoadResult();
  1. 调用要求

推荐调用,用户进入游戏并可以操作游戏时

DMP

zs.registerEvent

用户注册事件

  1. 方法
zs.registerEvent(Object object);
  1. 参数

Object object

属性类型默认值必填说明
pfstring登陆平台
userIdstring用户id
isSuccessboolean是否成功
  1. 调用要求

必须调用,如果游戏不需要注册,可以第一次进入游戏时调用

zs.loginEvent

用户登录事件

  1. 方法
zs.loginEvent(Object object);
  1. 参数

Object object

属性类型默认值必填说明
userIdstring用户id
  • 返回

  • 调用要求

必须上报,如果游戏不需要登录,可以在用户进入游戏时调用

zs.nextDayStayEvent

用户次留事件

  1. 方法
zs.nextDayStayEvent();
  1. 参数

  1. 调用要求

    必须上报

zs.payEvent

用户支付事件

  1. 方法
zs.payEvent(Object object);
  1. 参数

Object object

属性类型默认值必填说明
userIdstring用户id
contentTypestring""
contentNamestring""
contentIdstring""
contentNumbernumber1
paymentChannelstringzs
currencystringRMB
isSuccessbooleantrue支付状态。
currencyAmountnumber1支付金额,单位分。
  1. 调用要求

必须上报,如果没有支付事件,请用其它事件代替

SAS

zs.onPageStart

页面开始统计

  1. 方法
zs.onPageStart(string pageName);
  1. 参数

string pageName 页面名称

zs.onPageEnd

页面开始统计

  1. 方法
zs.onPageStart(string pageName);
  1. 参数
属性类型默认值必填说明
pageNamestring页面名称

zs.reportCustomProperty

用户自定义画像 如关卡、等级等

  1. 方法
zs.reportCustomProperty(string key, string|number value);
  1. 参数
属性类型默认值必填说明
keystring画像名称
valueany名称对应的值

zs.onEvent

自定义统计事件(目前支持talkingdata和mta事件)

zs.onEvent(string eventId, Object params);
属性类型默认值必填说明
eventIdstring事件Id
paramsobject{}事件参数

Ad

zs.createRewardedVideoAd

创建激励视频广告

  1. 方法
zs.createRewardedVideoAd(Object object);
  1. 参数

Object object

属性类型默认值必填说明
adUnitIdstring广告单元 id
multitonbooleanfalse是否启用多例模式,默认为false
  1. 返回值
类型说明
RewardedVideoAd激励视频广告组件,如果发生错误,有概率返回空
  1. 调用要求

激励视频加载时间较长,推荐进行预加载

zs.createInterstitialAd

创建插屏广告

  1. 方法
zs.createInterstitialAd(Object object);
  1. 参数

Object object

属性类型默认值必填说明
adUnitIdstring广告单元 id
  1. 返回值
类型说明
InterstitialAd插屏广告组件,如果发生错误,有概率返回空

zs.createBannerAd

创建横幅广告

  1. 方法
zs.createBannerAd(Object object);
  1. 参数

Object object

属性类型默认值必填说明
adUnitIdstring广告位id
adIntervalsnumber0广告自动刷新的间隔时间,单位为秒,参数值必须大于等于30(该参数不传入时 Banner 广告不会自动刷新)
styleObject广告的样式

object.style 的结构

属性类型必填说明
leftnumber广告的左上角横坐标
topnumber广告的左上角纵坐标
widthnumber广告的宽度
heightnumber广告的高度
  1. 返回值
类型说明
BannerAd横幅广告,如果发生错误,有概率返回空

zs.createNativeAd

创建原生广告

  1. 方法
zs.createNativeAd(Object object);
  1. 参数

Object object

属性类型默认值必填说明
adUnitIdstring广告位id
styleObject广告的样式
object.style 的结构
属性类型必填说明
leftnumber广告的左上角横坐标
topnumber广告的左上角纵坐标
widthnumber广告的宽度
heightnumber广告的高度
  1. 返回值
类型说明
NativeAd原生广告组件,如果发生错误,有概率返回空