### ZJSDK Initialization Example (Flutter)
Source: https://static-1318684143.cos-website.ap-shanghai.myqcloud.com/sdk-downloads/docs/flutter/android/init
Demonstrates the typical workflow for initializing and starting the ZJSDK in a Flutter application. It shows calling `initWithoutStart` first, then conditionally calling `start` based on user privacy consent, and handling the start-up callback.
```dart
/// 初始化SDK
void initSdk() {
ZJAndroid.initWithoutStart(TestPosId.appId,
customController: ZJCustomController(canUseAndroidId: true));
// 判断用户是否同意了隐私政策
if (_canStart) {
// 用于已同意隐私政策,调用启动方法,并在成功回调后调用广告
start();
} else {
// 展示隐私政策对话框,并在用户同意后调用`start`方法启动SDK
showPrivacyDialog(context);
}
}
/// 启动SDK
void start() {
ZJAndroid.start(onStartListener: (ret) {
if (ret.action == ZJEventAction.startSuccess) {
Fluttertoast.showToast(msg: "初始化成功");
} else {
Fluttertoast.showToast(msg: "初始化失败:" + ret.msg!); // "!" is used for non-null assertion, assuming ret.msg is never null when action is not startSuccess
if (kDebugMode) {
print("${ret.action}:${ret.code}");
}
}
});
}
```
--------------------------------
### SDK Initialization and Start
Source: https://static-1318684143.cos-website.ap-shanghai.myqcloud.com/sdk-downloads/docs/flutter/android/init
This section details the process of initializing and starting the ZJSDK. It involves calling `initWithoutStart` first to configure initialization information, followed by `start` after the user agrees to the privacy policy to launch the SDK. Ensure the SDK starts successfully before requesting ads.
```APIDOC
## Initialize and Start
Initialize the SDK using static methods of the `ZJAndroid` class after entering the application. The initialization process consists of two methods: `ZJAndroid#initWithoutStart` and `ZJAndroid#start`. These methods must be called sequentially. First, call `initWithoutStart` to configure the initialization information. Then, after the user agrees to the privacy policy, call `start` to launch the SDK. Ensure the SDK has started successfully before requesting ads.
### `initWithoutStart` Parameters
| Parameter | Type | Description |
| ----------------- | ----------------------------------- | ------------------------------------------------------------------------------- |
| `appId` | string | Media ID |
| `customController`| `ZJCustomController` | Privacy control (refer to Privacy Information Control) |
| `isDebug` | bool | Debug mode: outputs debug logs. Defaults to `true`. |
| `age` | int | User age, for overseas markets only. Must be greater than 0. Defaults to `0`. |
| `gdpr` | int | GDPR authorization, for overseas markets only. -1: unknown, 0: not authorized, 1: authorized. Defaults to `-1`. |
| `coppa` | int | COPPA authorization, for overseas markets only. -1: unknown, 0: adult, 1: child. Defaults to `-1`. |
| `ccpa` | int | CCPA authorization, for overseas markets only. -1: unknown, 0: allow sale, 1: do not allow sale. Defaults to `-1`. |
### `start` Parameters
| Parameter | Type | Description |
| ----------------- | ----------------------------------- | ------------------------------------------------------------------------------- |
| `onStartListener` | Function(ZJEvent ret)? | Callback event for start status. |
### Initialization Example
```dart
/// Initialize the SDK
void initSdk() {
ZJAndroid.initWithoutStart(TestPosId.appId,
customController: ZJCustomController(canUseAndroidId: true));
// Check if the user has agreed to the privacy policy
if (_canStart) {
// User has agreed to the privacy policy, call the start method and request ads after successful callback
start();
} else {
// Display the privacy policy dialog and call the `start` method to initialize the SDK after the user agrees
showPrivacyDialog(context);
}
}
/// Start the SDK
void start() {
ZJAndroid.start(onStartListener: (ret) {
if (ret.action == ZJEventAction.startSuccess) {
Fluttertoast.showToast(msg: "Initialization successful");
} else {
Fluttertoast.showToast(msg: "Initialization failed: " + ret.msg!);
if (kDebugMode) {
print("${ret.action}:${ret.code}");
}
}
});
}
```
```
--------------------------------
### Configure LSApplicationQueriesSchemes for App Integration (XML)
Source: https://static-1318684143.cos-website.ap-shanghai.myqcloud.com/sdk-downloads/docs/flutter/ios/import
This XML snippet shows how to add a list of URL schemes to the LSApplicationQueriesSchemes key in an iOS application's Info.plist file. This configuration enables the application to query for the presence of other installed applications on the user's device, which is essential for deep linking and conditional logic based on the user's environment. It supports a wide range of popular applications, enhancing interoperability and user experience.
```xml
LSApplicationQueriesSchemes
alipayauth
alipays
alipay
wechat
weixin
taobao
tbopen
openapp.jdmobile
pinduoduo
meituanwaimai
imeituan
snssdk1128
kwai
cydia
sinaweibo
dianping
xhsdiscover
bilibili
baiduboxapp
tmall
fleamarket
eleme
OneTravel
onetravel
quark
youku
uppaywallet
luckycoffee
orpheus
ziroom
openanjuke
fdd
soufun
lianjia
lianjiabeike
cainiao
bytedance
soul
weixinULAPI
mqq
mqqapi
mqqopensdkapiV2
mqqopensdkapiV4
jdmobile
openjdlite
openapp.jdpingou
taobaolite
taobaolive
taobaotravel
ctrip
palfish-read
douyutv
sinaweibohd
weibosdk
baidumobads
itms-beta
pddopen
snssdk35
snssdk1112
snssdk2329
snssdk141
vipshop
dewuapp
suning
suningebuy
com.suning.SuningEBuy
iting
baiduhaokan
usage_crazyreader
pajkdoctor
qunariphone
qunaraphone
QunarAlipay
mttbrowser
dragon1967
ttnewssso
wbmain
awemesso
douyinopensdk
mp1089867489
sohuvideo-iphone
momochat
bdboxiosqrcode
freereader
ucbrowser
gifshow
weishiiosscheme
qqnews
qmkege
yymobile
yykiwi
sinanews
paesuperbank
qiyi-iphone
iqiyi
baidumap
openanjuke
bds
shuabao
orpheuswidget
qqmusic
zhihu
cmblife
iosamap
sinafinance
zhwnl
kugouURL
ksnebula
BaiduIMShop
com.sogou.sogouinput
tenvideo
qmtoken
dzhiphone
doubanradio
amihexin
rm434209233MojiWeather
com.kuwo.kwmusic.kwmusicForKwsing
camcard
camscanner
com.kingsoft.powerword.6
comIfeng3GifengNews
buka
yddictproapp
gtgj
elongiPhone
baiduvideoiphone
wireless1688
bitauto.yicheapp
app.soyoung
weiyun
xunlei
mdopen
mdsopen
flyreader
novelfm3040luckydog
baiduboxlite
quantgroup
tantanapp
usagecrazyreaderios
dingdongneighborhood
duapp
hlluapp
msec
bosszp
tuhu
bdminivideo
shuqireader
txvideo
baiduboxmission
com.baidu.tieba
qihooloan
travelguide
kaola
tomas
secoo
```
--------------------------------
### Start ZJSDK Services (Flutter)
Source: https://static-1318684143.cos-website.ap-shanghai.myqcloud.com/sdk-downloads/docs/flutter/android/init
Starts the ZJSDK services after initialization and after the user has granted privacy policy consent. This method accepts an optional `onStartListener` callback to receive feedback on the start-up status, including success or failure events with error codes and messages.
```dart
class ZJAndroid {
/// 启动SDK
/// 需要在用户同意隐私政策之后尽快调用
static void start({
/// 启动回调
/// [ret.event] {ZJEventAction.startSuccess | ZJEventAction.startFailed},启动失败时,需要解析ret.code等信息排查
/// [ret.code] 错误码
/// [ret.msg] 错误描述
Function(ZJEvent ret)? onStartListener});
}
```
--------------------------------
### Initialize ZJSDK Without Starting (Flutter)
Source: https://static-1318684143.cos-website.ap-shanghai.myqcloud.com/sdk-downloads/docs/flutter/android/init
Initializes the ZJSDK with configuration parameters without immediately starting its services. This method is suitable for calling before user consent for privacy policies. It requires an `appId` and accepts optional parameters for debugging, GDPR, COPPA, CCPA, user age, and a custom privacy controller.
```dart
class ZJAndroid {
/// 初始化SDK
/// 可以在进入应用后立即调用
/// 返回是否初始化成功
static void initWithoutStart(
/// 应用ID
String appId,
{
/// 控制日志打印
bool isDebug = true,
/// gdpr状态,-1为未知,0为用户未授权,1为用户授权
int gdpr = -1,
/// coppa状态,-1为未知,0为成人,1为儿童
int coppa = -1,
/// ccpa状态,-1为未知,0为允许出售,1为不允许出售
int ccpa = -1,
/// 用户年龄,默认为0
int age = 0,
/// 隐私权限控制
ZJCustomController? customController});
}
```
--------------------------------
### Integrate Video Stream Ad in Flutter Example
Source: https://static-1318684143.cos-website.ap-shanghai.myqcloud.com/sdk-downloads/docs/flutter/android/draw_ad
Provides an example of integrating the ZJDrawAdView component into a Flutter application. It demonstrates how to set the ad unit ID, dimensions, and handle ad events like errors, display, clicks, and closure using a switch statement.
```dart
child: ZJDrawAdView(
// 广告位ID
posId,
width: double.infinity,
height: double.infinity,
drawAdListener: (ret) {
switch (ret.action) {
// 广告错误
case ZJEventAction.onAdError:
Fluttertoast.showToast(msg: "视频流错误:${ret.msg}");
if (kDebugMode) {
print("${ret.action}:${ret.code}-${ret.msg}");
}
break;
// 展示成功
case ZJEventAction.onAdShow:
Fluttertoast.showToast(msg: "视频流展示");
break;
// 点击广告
case ZJEventAction.onAdClick:
Fluttertoast.showToast(msg: "视频流点击");
break;
// 关闭
case ZJEventAction.onAdClose:
Fluttertoast.showToast(msg: "视频流关闭");
break;
default:
// ignore
}
},
),
```
--------------------------------
### Configure Xcode Info.plist for HTTP Permissions
Source: https://static-1318684143.cos-website.ap-shanghai.myqcloud.com/sdk-downloads/docs/flutter/ios/import
This configuration in Xcode's Info.plist file is necessary to allow arbitrary loads, which is required because some advertiser materials may not be HTTPS. It ensures the SDK can load all necessary resources.
```xml
NSAppTransportSecurity
NSAllowsArbitraryLoads
```
--------------------------------
### Add ZJSDK Dependency to Flutter Project
Source: https://static-1318684143.cos-website.ap-shanghai.myqcloud.com/sdk-downloads/docs/flutter/android/import
Demonstrates how to add the ZJSDK Android plugin to a Flutter project. It provides two methods: using `flutter pub add` or manually editing `pubspec.yaml` and running `flutter pub get`.
```yaml
dependencies:
zjsdk_android: '>=2.5.0 <2.6.0'
```
--------------------------------
### Get ZJ SDK Version
Source: https://static-1318684143.cos-website.ap-shanghai.myqcloud.com/sdk-downloads/docs/flutter/ios/new_playlet_ad
Retrieve the current version of the ZJ SDK using the `getSDKVersion` method. The version information is returned via a callback function.
```dart
ZjPlayletPlugin.getSDKVersion(onCallback: (version) {
print('====>>>>>$version');
});
```
--------------------------------
### Initialize ZJSDK in Flutter
Source: https://static-1318684143.cos-website.ap-shanghai.myqcloud.com/sdk-downloads/docs/flutter/ios/new_init
Demonstrates how to initialize the ZJSDK in a Flutter project. It requires an application ID and an ad unit ID, which should be obtained from the operations team. The initialization callback handles success and failure events. A custom controller can be provided to manage SDK permissions.
```dart
/**
IosZJCustomController属性说明,默认值为true
/// 是否允许SDK使用定位权限
final bool canUseLocation;
/// 是否允许SDK使用WiFi BSSID
final bool canUseWiFiBSSID;
/// 是否允许SDK获取IDFA
final bool canUseIDFA;
/// 是否允许SDK获取IDFV
final bool canUseIDFV;
/// 是否允许获取手机状态信息
final bool canUsePhoneStatus;
/// 收否允许获取手机DeviceId
final bool canUseDeviceId;
/// 是否允许获取手机系统版本名
final bool canUseOSVersionName;
/// 是否允许获取手机系统版本号
final bool canUseOSVersionCode;
/// 是否允许获取手机应用包名
final bool canUsePackageName;
/// 是否允许获取手机应用版本名
final bool canUseAppVersionName;
/// 是否允许获取手机应用版本号
final bool canUseAppVersionCode;
/// 是否允许获取手机设备品牌
final bool canUseBrand;
/// 是否允许获取手机设备型号
final bool canUseModel;
/// 是否允许获取手机屏幕分辨率
final bool canUseScreen;
/// 是否允许获取手机屏幕方向
final bool canUseOrient;
/// 是否允许获取手机网络类型
final bool canUseNetworkType;
/// 是否允许获取手机移动网络代码
final bool canUseMNC;
/// 是否允许获取手机移动国家代码
final bool canUseMCC;
/// 是否允许获取手机系统语言
final bool canUseOSLanguage;
/// 是否允许获取手机时区
final bool canUseTimeZone;
/// 是否允许获取手机User Agent
final bool canUseUserAgent;
/// 是否允许SDK主动使用互动组件能力(摇一摇、扭一扭等)
final bool isCanUseMotionManager;
*/
IosZJCustomController customController = IosZJCustomController(
canUseIDFA: false,
);
ZjsdkFlutter.registerAppId("zj_20201014iOSDEMO", (ret) {
switch (ret.action) {
case IosZjEventAction.initSuccess:
print('初始化成功');
break;
case IosZjEventAction.initFailed:
print('初始化失败');
break;
default:
}
}, customController: customController);
```
--------------------------------
### Get ZJSDK Version
Source: https://static-1318684143.cos-website.ap-shanghai.myqcloud.com/sdk-downloads/docs/flutter/ios/new_init
Retrieves the current version of the ZJSDK. This is a simple asynchronous call that returns the SDK version as a string.
```dart
var sdkVersion = await ZjsdkFlutter.sdkVersion;
```
--------------------------------
### Configure Xcode Build Settings for Linker Flags
Source: https://static-1318684143.cos-website.ap-shanghai.myqcloud.com/sdk-downloads/docs/flutter/ios/import
This setting in Xcode's Build Settings requires adding the '-ObjC' flag to 'Other Linker Flags'. This is crucial for the correct linking of Objective-C code within the SDK.
```bash
-ObjC
```
--------------------------------
### Specify SDK Version for Flutter Project
Source: https://static-1318684143.cos-website.ap-shanghai.myqcloud.com/sdk-downloads/docs/flutter/android/import
Defines the required SDK version range for a Flutter project. This ensures compatibility with the ZJSDK and its features, specifically mentioning the 'enhanced Enum' requirement.
```yaml
environment:
sdk: ">=2.17.0 <3.0.0"
```
--------------------------------
### Configure Info.plist for iOS ATT Permissions
Source: https://static-1318684143.cos-website.ap-shanghai.myqcloud.com/sdk-downloads/docs/flutter/ios/import
This snippet shows the necessary addition to your application's Info.plist file to comply with iOS 14.5+ App Tracking Transparency requirements. The `NSUserTrackingUsageDescription` key with a custom string is mandatory for requesting user permission to track.
```xml
NSUserTrackingUsageDescription
该标识符将用于向您投放个性化广告
```
--------------------------------
### Configure Android Manifest for ZJSDK
Source: https://static-1318684143.cos-website.ap-shanghai.myqcloud.com/sdk-downloads/docs/flutter/android/import
Provides necessary configurations for the AndroidManifest.xml file when integrating ZJSDK. This is crucial for projects with `minSdkVersion < 24` and ensures correct SDK functionality by specifying override libraries and application replacements.
```xml
```
--------------------------------
### Configure Xcode Info.plist for Location Permissions
Source: https://static-1318684143.cos-website.ap-shanghai.myqcloud.com/sdk-downloads/docs/flutter/ios/import
These keys in the application's Info.plist file are required to request location permissions from the user. This helps the SDK provide more accurate ad matching and prevents potential rejections during App Store review.
```plist
Privacy - Location When In Use Usage Description
Privacy - Location Always and When In Use Usage Description
Privacy - Location Always Usage Description
Privacy - Location Usage Description
```
--------------------------------
### Add ZJSDK Flutter Package to pubspec.yaml
Source: https://static-1318684143.cos-website.ap-shanghai.myqcloud.com/sdk-downloads/docs/flutter/ios/import
This snippet shows how to add the ZJSDK Flutter package to your project's pubspec.yaml file. This is the recommended method for most Flutter developers due to its simplicity and efficiency.
```yaml
zjsdk_flutter: ^0.2.2
```
--------------------------------
### Initialize ZJSDK with Custom Privacy Controls (Flutter)
Source: https://static-1318684143.cos-website.ap-shanghai.myqcloud.com/sdk-downloads/docs/flutter/android/private_data
This Dart code defines a `ZJCustomController` class for configuring various privacy permissions when initializing the ZJSDK using `initWithoutStart()`. Developers can selectively enable or disable access to location, phone state, device IDs, network state, storage, installed packages, audio recording, boot ID, Wi-Fi information, sensors, and SIM operator details. Default values are provided for most properties, assuming broader permissions unless explicitly set to false.
```dart
/// Privacy permission control
class ZJCustomController {
static const List defaultInstalledPackages = [];
/// Active location acquisition
final bool canReadLocation;
/// Longitude
final double longitude;
/// Latitude
final double latitude;
/// Active device information acquisition
final bool canUsePhoneState;
/// IMEI
final String imei;
/// Active AndroidID acquisition
final bool canUseAndroidId;
/// AndroidID
final String androidId;
/// Active MAC address acquisition
final bool canUseMacAddress;
/// MAC address
final String macAddress;
/// Active OAID acquisition
final bool canUseOaid;
/// OAID/GAID
final String oaid;
/// Network state acquisition
final bool canUseNetworkState;
/// Storage usage
final bool canUseStoragePermission;
/// Active reading of installed application list
final bool canReadInstalledPackages;
/// Installed application list
final List installedPackages;
/// Whether the SDK is allowed to use the recording permission when declared and authorized
bool canRecordAudio;
/// Whether the SDK is allowed to actively obtain BootID
bool canReadBootId;
/// Whether to allow obtaining the nearby Wifi list
bool canReadNearbyWifiList;
/// Whether to allow obtaining sensor information
bool canUseSensor;
/// Whether to allow the SDK to actively obtain operator information
bool canUseSimOperator;
/// When canUseSimOperator==false, the operator code can be passed, for example: 46000
final String simOperatorCode;
/// When canUseSimOperator==false, the operator name can be passed, for example: China Mobile
final String simOperatorName;
ZJCustomController({
this.canReadLocation = true,
this.longitude = 0.0000,
this.latitude = 0.0000,
this.canUsePhoneState = true,
this.imei = "",
this.canUseAndroidId = true,
this.androidId = "",
this.canUseMacAddress = true,
this.macAddress = "",
this.canUseOaid = true,
this.oaid = "",
this.canUseNetworkState = true,
this.canUseStoragePermission = true,
this.canReadInstalledPackages = true,
this.installedPackages = defaultInstalledPackages,
this.canRecordAudio = true,
this.canReadBootId = true,
this.canReadNearbyWifiList = true,
this.canUseSensor = true,
this.canUseSimOperator = true,
this.simOperatorCode = "",
this.simOperatorName = ""
});
}
```
--------------------------------
### Enable/Disable Programmatic Recommendations (ZJSDK)
Source: https://static-1318684143.cos-website.ap-shanghai.myqcloud.com/sdk-downloads/docs/flutter/ios/new_init
Controls the programmatic recommendation feature for the ZJSDK. This setting should be configured before initializing the SDK. It accepts a boolean value, where `true` enables recommendations and `false` disables them. The default value is `true`.
```dart
ZjsdkFlutter.setProgrammaticRecommend(true);
```
--------------------------------
### Integrate ZJTubeAdView in Flutter Application
Source: https://static-1318684143.cos-website.ap-shanghai.myqcloud.com/sdk-downloads/docs/flutter/android/tube_ad
Provides an example of integrating the ZJTubeAdView widget within a Flutter application. This snippet demonstrates how to configure various properties such as ad unit ID, dimensions, user ID, and callback handlers for unlock results, creation events, general ad events, page events, and video events.
```dart
child: ZJTubeAdView(
posId,
width: double.infinity,
height: double.infinity,
config: ZJTubeAdConfig(
userId: TestPosId.testUserId, isHideTitleBar: true),
// 禁用SDK自带的解锁对话框时,需要展示自定义解锁对话框并返回用户是否同意的状态
showCustomUnlockDialogCallback: _showCustomUnlockDialog,
// 短剧解锁结果回调
unlockCallback: _onUnlockCallback,
onCreatedCallback: _onTubeAdViewCreated,
tubeAdListener: (ret) {
if (ret.action == ZJEventAction.onAdError) {
Fluttertoast.showToast(msg: "视频内容错误:${ret.msg}");
if (kDebugMode) {
print("${ret.action}:${ret.code}-${ret.msg}");
}
_reset();
}
},
pageEventCallback: (event, adItem) {
Fluttertoast.showToast(msg: "页面事件: $event - id: ${adItem.id}");
print("TubeAdPageEventCallback: event=${event} & adItem = ${adItem.toString()}");
},
videoEventCallback: (event, adItem) {
// Fluttertoast.showToast(msg: "视频事件: $event - id: ${adItem.id}");
print("TubeAdVideoEventCallback: event=${event} & adItem = ${adItem.toString()}");
},
)
/// 展示短剧组件到容器中
void _show() {
if (controller == null) {
setState(() {
showTubeView = true;
});
} else {
controller!.show();
}
}
/// 隐藏短剧组件
void _hide() {
if (controller == null) {
Fluttertoast.showToast(msg: "还未加载成功");
} else {
// 隐藏
controller!.hide();
}
}
/// 禁用SDK自带的解锁对话框时,需要展示自定义解锁对话框并返回用户是否同意的状态
Future _showCustomUnlockDialog(ZJTubeAdItem adItem) async {
Completer completer = Completer();
/// 在展示自定义解锁对话框后回调结果
completer.complete(Random().nextBool()); // 此处模拟用户随机同意/取消解锁
return completer.future;
}
/// 短剧解锁结果回调
/// 成功时code==0,msg==null
/// 失败时code!=0,msg!=null
/// 失败事件不一定触发,成功事件一定触发
void _onUnlockCallback(bool isSuccess, int errCode, String? errMsg) {
if (isSuccess) {
Fluttertoast.showToast(msg: "解锁成功");
} else {
Fluttertoast.showToast(msg: "解锁失败[$errCode-$errMsg]");
}
}
/// 以Widget加载时的组件控制器
void _onTubeAdViewCreated(ZJTubeAdViewController controller) {
this.controller = controller;
// 在创建视图成功后,需要配置解锁需要的广告位ID(仅支持激励广告和插全屏广告)
this.controller!.setUnlockAdPosId(Random().nextBool()
? TestPosId.rewardVideoPosId
: TestPosId.interstitialPosId);
}
```
--------------------------------
### Request IDFA Advertising Permissions on iOS (Objective-C)
Source: https://static-1318684143.cos-website.ap-shanghai.myqcloud.com/sdk-downloads/docs/flutter/ios/import
This Objective-C code snippet demonstrates how to request user tracking authorization using the App Tracking Transparency framework on iOS 14.0 and above. It retrieves the IDFA if authorization is granted and provides fallback logic for older iOS versions. Ensure AdSupport.framework and AppTrackingTransparency.framework are linked.
```objectivec
#import
#import
- (void)applicationDidBecomeActive:(UIApplication *)application {
if (@available(iOS 14.0, *)) {
// iOS14及以上版本需要先请求权限
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
// 获取到权限后,依然使用老方法获取idfa
if (status == ATTrackingManagerAuthorizationStatusAuthorized) {
NSString *idfa = [[ASIdentifierManager sharedManager].advertisingIdentifier UUIDString];
} else {
NSLog(@"请在设置-隐私-跟踪中允许App请求跟踪");
}
}];
});
} else {
// iOS14以下版本依然使用老方法
// 判断在设置-隐私里用户是否打开了广告跟踪
if ([[ASIdentifierManager sharedManager] isAdvertisingTrackingEnabled]) {
NSString *idfa = [[ASIdentifierManager sharedManager].advertisingIdentifier UUIDString];
} else {
NSLog(@"请在设置-隐私-广告中打开广告跟踪功能");
}
}
}
```
--------------------------------
### Request IDFA Advertising Permissions on iOS (Swift)
Source: https://static-1318684143.cos-website.ap-shanghai.myqcloud.com/sdk-downloads/docs/flutter/ios/import
This Swift code snippet shows how to request user tracking authorization using the App Tracking Transparency framework on iOS 14.0 and above. It handles different authorization statuses and is intended to be called within `applicationDidBecomeActive`. The code includes a delay to help with App Store submission.
```swift
import AdSupport
import AppTrackingTransparency
override func applicationDidBecomeActive(_ application: UIApplication) {
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
if #available(iOS 14.0, *) {
AppTrackingManager.requestTrackingAuthorization { status in
switch status {
case .authorized:
print("用户授权跟踪")
case .denied:
print("用户拒绝授权")
case .restricted:
print("跟踪被限制")
case .notDetermined:
print("用户尚未决定")
@unknown default:
print("未知的跟踪状态")
}
}
}
}
}
```
--------------------------------
### Initialize ZJ Playlet Plugin
Source: https://static-1318684143.cos-website.ap-shanghai.myqcloud.com/sdk-downloads/docs/flutter/ios/new_playlet_ad
Initialize the ZJ Playlet SDK by calling the `registerAppId` method with your media ID before loading any ads. A callback function is provided to receive initialization results and messages.
```dart
ZjPlayletPlugin.registerAppId(
"媒体ID",
onCallback: (result, msg) {
print('------初始化结果$result, 初始化消息$msg');
},
);
```
--------------------------------
### Add SKAdNetwork IDs to Info.plist (XML)
Source: https://static-1318684143.cos-website.ap-shanghai.myqcloud.com/sdk-downloads/docs/flutter/ios/import
This XML snippet demonstrates how to add SKAdNetwork IDs to your application's Info.plist file. This is crucial for enabling SKAdNetwork to correctly track conversions and attribute app installs, especially when IDFA is not available. Ensure all relevant SKAdNetworkIdentifier entries are included within the SKAdNetworkItems array.
```xml
SKAdNetworkItems
SKAdNetworkIdentifier
238da6jt44.skadnetwork
SKAdNetworkIdentifier
x2jnk7ly8j.skadnetwork
SKAdNetworkIdentifier
f7s53z58qe.skadnetwork
SKAdNetworkIdentifier
58922NB4GD.skadnetwork
SKAdNetworkIdentifier
kbd757ywx3.skadnetwork
SKAdNetworkIdentifier
22mmun2rn5.skadnetwork
SKAdNetworkIdentifier
r3y5dwb26t.skadnetwork
SKAdNetworkIdentifier
cstr6suwn9.skadnetwork
```
--------------------------------
### Load ZJContentPage Widget with Callbacks (Flutter)
Source: https://static-1318684143.cos-website.ap-shanghai.myqcloud.com/sdk-downloads/docs/flutter/ios/new_content_page_ad
Demonstrates how to instantiate and configure the IosZjContentAdView widget for displaying video content. It includes parameters for ad unit ID, dimensions, and a comprehensive callback function to handle various video playback and content display events. This widget is part of the ZJSDK for Flutter.
```dart
/**
* 参数1: 视频内容的广告位ID
* 参数2: 视频内容展示的宽度
* 参数3: 视频内容展示的高度
* 参数4: 视频内容的事件回调
*/
IosZjContentAdView(
"K90010005",
width: maxWidth,
height: maxHeight,
contentAdListener: (ret) {
switch (ret.action) {
case IosZjEventAction.onAdLoaded:
print('视频内容加载了');
break;
case IosZjEventAction.onAdError:
print('视频内容报错');
break;
case IosZjEventAction.onAdCloseOtherController:
print('视频内容详情页关闭');
break;
case IosZjEventAction.onVideoDidStartPlay:
print('视频内容开始播放');
break;
case IosZjEventAction.onVideoDidPausePlay:
print('视频内容暂停播放');
break;
case IosZjEventAction.onVideoDidResumePlay:
print('视频内容恢复播放');
break;
case IosZjEventAction.onVideoDidEndPlay:
print('视频内容停止播放');
break;
case IosZjEventAction.onVideoDidFailedToPlay:
print('视频内容播放失败');
break;
case IosZjEventAction.onContentDidFullDisplay:
print('视频内容内容展示');
break;
case IosZjEventAction.onContentDidEndDisplay:
print('视频内容内容隐藏');
break;
case IosZjEventAction.onContentDidPause:
print('视频内容内容暂停显示');
break;
case IosZjEventAction.onContentDidResume:
print('视频内容内容恢复显示');
break;
default:
}
},
);
```
--------------------------------
### Load Short Playlet Ad (Native)
Source: https://static-1318684143.cos-website.ap-shanghai.myqcloud.com/sdk-downloads/docs/flutter/ios/new_playlet_ad
Load a short playlet ad using the native approach. This involves providing an ad unit ID, a JSON configuration file, and specifying free/unlocked episode counts. Various callback events for ad loading and playback are handled.
```dart
// 引入文件
import 'package:zj_playlet_plugin/zj_playlet_plugin.dart';
// 短剧的加载 memungkinkanPlayletPlugin.loadPlayletAd(
"广告位ID",
"申请的XXX.json文件",
1, // 代表免费观看的集数
2, // 广告解锁集数
hideLikeIcon: false, // 是否隐藏喜欢按钮,true代表隐藏,false代表不隐藏
hideCollectIcon: false, // 是否隐藏收藏按钮,true代表隐藏,false代表不隐藏
disableDoubleClickLike: false, // 是否禁用双击手势,true代表禁用,false代表不禁用
disableLongPressSpeed: true, // 是否禁用长按手势,true代表禁用,false代表不禁用
// 下面adType和posId代表设置自己的激励广告,如果不设置,短剧会加载默认广告,adType的值1代表激励,0代表插屏
// adType: 1,
// posId: "激励广告位",
onCallback: (type, msg) { // type代表事件名,msg代表参数
switch (type) {
case "PlayletLoadSuccess":
print("短剧加载成功PlayletLoadSuccess");
break;
case "PlayletLoadFailure":
print("短剧加载失败PlayletLoadFailure");
break;
case "VideoDidStartPlay":
print("视频开始播放");
break;
case "VideoDidPause":
print("视频暂停播放");
break;
case "VideoDidResume":
print("视频恢复播放");
break;
case "VideoDidEndPlay":
print("视频停止播放");
break;
case "ShortplayPlayletDetailUnlockFlowStart":
print("解锁流程开始");
break;
case "ShortplayPlayletDetailUnlockFlowCancel":
print("解锁流程取消");
break;
case "ShortplayPlayletDetailUnlockFlowEnd":
print("解锁流程结束,回调解锁结果, success: 是否解锁成功 == $msg");
break;
case "ShortplayClickEnterView":
print(" 点击混排中进入跳转播放页的按钮");
break;
case "ShortplayNextPlayletWillPlay":
print("本剧集观看完毕,切到下一部短剧回调");
break;
case "ShortplaySendAdRequest":
print("发起广告请求");
break;
case "ShortplayAdLoadSuccess":
print("广告加载成功");
break;
case "ShortplayAdLoadFail":
print("广告加载失败");
break;
case "ShortplayAdFillFail":
print("广告填充失败");
break;
case "ShortplayAdWillShow":
print("广告曝光");
break;
case "ShortplayClickAdView":
print("点击广告");
break;
case "ShortplayVideoRewardFinish":
print("激励视频广告结束");
break;
case "ShortplayVideoRewardSkip":
print("激励视频广告跳过");
break;
case "ShortplayDrawVideoCurrentVideoChanged":
print("视频切换时的回调 == $msg");
break;
case "ShortplayDrawVideoDidClickedErrorButtonRetry":
print("加载失败按钮点击重试回调");
break;
case "ShortplayDrawVideoCloseButtonClicked":
print("默认关闭按钮被点击的回调");
break;
case "ShortplayDrawVideoDataRefreshCompletion":
print("数据刷新完成回调");
break;
// 以下添加自己需要的方法回调判断,事件类型参照ZjPlayletPlugin文件的事件类型说明
default:
break;
}
},
);
```
--------------------------------
### Show Short Playlet Ad (Native)
Source: https://static-1318684143.cos-website.ap-shanghai.myqcloud.com/sdk-downloads/docs/flutter/ios/new_playlet_ad
After loading a short playlet ad using the native method, display it by calling the `showPlayletAd` method.
```dart
ZjPlayletPlugin.showPlayletAd();
```
--------------------------------
### Enable/Disable Personalized Recommendations (ZJSDK)
Source: https://static-1318684143.cos-website.ap-shanghai.myqcloud.com/sdk-downloads/docs/flutter/ios/new_init
Controls the personalized recommendation feature for the ZJSDK. This setting should be configured before initializing the SDK. It accepts a boolean value, where `true` enables recommendations and `false` disables them. The default value is `true`.
```dart
ZjsdkFlutter.setPersonalRecommend(true);
```
--------------------------------
### Configure Programmatic Recommendation State with ZJSDK (Android)
Source: https://static-1318684143.cos-website.ap-shanghai.myqcloud.com/sdk-downloads/docs/flutter/android/private_data
This method enables developers to manage the state of programmatic recommendations. Similar to personalized recommendations, the application should track the state and invoke this method upon any change. The SDK must be initialized prior to this call. It accepts a boolean parameter to enable or disable programmatic recommendations.
```java
ZJAndroid.setProgrammaticRecommend(bool state);
```
--------------------------------
### Register Method Channel for Short Playlets
Source: https://static-1318684143.cos-website.ap-shanghai.myqcloud.com/sdk-downloads/docs/flutter/ios/new_playlet_ad
Before using the ZJ Playlet plugin's features, register the method channel at your application's entry point. This step is crucial for communication between the Flutter app and the native SDK.
```dart
// 新增注册方法通道
ZjPlayletPlugin.registerMethodChannel();
```
--------------------------------
### 原生视频内容接入示例 (Flutter/Dart)
Source: https://static-1318684143.cos-website.ap-shanghai.myqcloud.com/sdk-downloads/docs/flutter/android/content_ad
这是一个原生视频内容接入的 Flutter 示例。它定义了一个 `_loadContentAd` 函数,用于调用 `ZJAndroid.contentAd` 并处理回调事件。回调事件包括广告错误 (`onAdError`) 和广告关闭 (`onAdClose`),并使用 `Fluttertoast` 显示相应的提示信息。在广告错误时,还会打印详细的错误信息到控制台。
```dart
/// 原生加载广告
void _loadContentAd(String posId) {
ZJAndroid.contentAd(
// 广告位ID
posId,
contentAdListener: (ret) {
switch (ret.action) {
case ZJEventAction.onAdError:
Fluttertoast.showToast(msg: "视频内容错误:${ret.msg}");
if (kDebugMode) {
print("${ret.action}:${ret.code}-${ret.msg}");
}
break;
case ZJEventAction.onAdClose:
Fluttertoast.showToast(msg: "视频内容关闭");
break;
default:
// ignore
}
}
);
}
```
--------------------------------
### Add SKAdNetwork IDs to Info.plist (Comments)
Source: https://static-1318684143.cos-website.ap-shanghai.myqcloud.com/sdk-downloads/docs/flutter/ios/import
This code snippet provides comments explaining how to add SKAdNetwork IDs to your Info.plist file. It lists the SKAdNetworkIdentifier for several ad networks, including Guangdiantong, Kuaishou, Sigmob, MTG, Chuanshanjia, and Google. These identifiers are necessary for SKAdNetwork to function correctly.
```objective-c
//将SKAdNetwork ID 添加到 info.plist 中,以保证 SKAdNetwork 的正确运行
//广点通
//SKAdNetworkIdentifier : f7s53z58qe.skadnetwork
//快手
//SKAdNetworkIdentifier : r3y5dwb26t.skadnetwork
//sigmob
//SKAdNetworkIdentifier : 58922NB4GD.skadnetwork
//MTG
//SKAdNetworkIdentifier : kbd757ywx3.skadnetwork
//穿山甲
//SKAdNetworkIdentifier : 238da6jt44.skadnetwork
//SKAdNetworkIdentifier : x2jnk7ly8j.skadnetwork
//SKAdNetworkIdentifier : 22mmun2rn5.skadnetwork
//Google
//SKAdNetworkIdentifier : cstr6suwn9.skadnetwork
```