最近更新:2023-8-17
展开全部
SDK说明
资源文件
- Libs 文件夹:包含头文件 JAdService.h,静态库文件 jad-ios-x.x.x.a,jbasic-ios-x.x.x.xcframework
- Demo 文件夹:示例
适用版本
本文匹配的 SDK 版本:r5.0.0 以后。 查看最近更新了解最新的 SDK 更新情况。
创建应用
- 在 JPush 的管理 Portal 上创建应用,创建成功后自动生成 Appkey 用以标识该应用。
- 开发者后台 》创建应用 》iOS》选择"消息推送"》配置BundleID
配置工程
导入 SDK
选择 1:Cocoapods 导入
1.如果使用标准版本(需要特别注意以下“注意事项”)
pod 'JCore', '4.2.8-jbasic' //使用 JCore 的 jbasic 版本(x.x.x-jbasic)
pod 'JAd'
注:如果无法导入最新版本,请执行 pod repo update master 这个命令来升级本机的 pod 库,然后重新 pod 'JAd'
pod 'JCore', '4.2.8-jbasic' //使用 JCore 的 jbasic 版本(x.x.x-jbasic)
pod 'JAd'
注:如果无法导入最新版本,请执行 pod repo update master 这个命令来升级本机的 pod 库,然后重新 pod 'JAd'
此代码块在浮窗中显示
2.如果需要安装指定版本则使用以下方式(以 JAd 5.0.2 版本为例):
pod 'JCore', '4.2.8-jbasic' //使用 JCore 的 jbasic 版本(x.x.x-jbasic)
pod 'JAd', '5.0.2'
pod 'JCore', '4.2.8-jbasic' //使用 JCore 的 jbasic 版本(x.x.x-jbasic)
pod 'JAd', '5.0.2'
此代码块在浮窗中显示
若同时集成 推送/认证/分析,请使用 JCore 标准版本或者无 IDFA 版本。
- 标准版本: pod 'JCore', '4.2.8'
- 无 IDFA 版本: pod 'JCore', '4.2.8-noidfa'
选择 2:手动导入
- 在极光联盟开发者者后台下载SDK接入
- 将 SDK 包解压,在 Xcode 中选择 “Add files to 'Your project name'…”,将解压后的 Libs 子文件夹里的 JAdService.h、jad-ios-x.x.x.a、jbasic-ios-x.x.x.xcframework 添加到你的工程目录中。
- 若同时集成 推送/认证/分析,只需要添加JCore包,不要添加JBasic包。
- 添加 Framework
- CFNetwork.framework
- CoreFoundation.framework
- CoreTelephony.framework
- SystemConfiguration.framework
- CoreGraphics.framework
- Foundation.framework
- UIKit.framework
- Security.framework
- libz.tbd(Xcode 7 以下版本是 libz.dylib)
- libresolv.tbd(Xcode 7 以下版本是 libresolv.dylib)
- WebKit.framework
- StoreKit.framework
- AdSupport.framework(获取 IDFA 需要;如果不使用 IDFA,请不要添加)
- AppTrackingTransparency.framework(Xcode 12及以上,获取 IDFA 需要;如果不使用 IDFA,请不要添加)
接入代码
添加头文件
请将以下代码添加到 AppDelegate.m 引用头文件的位置。
// 引入 JAd 功能所需头文件
#import "JAdService.h"
// 如果需要使用 idfa 功能所需要引入的头文件(可选)
#import <AdSupport/AdSupport.h>
#import <AppTrackingTransparency/AppTrackingTransparency.h>
// 引入 JAd 功能所需头文件
#import "JAdService.h"
// 如果需要使用 idfa 功能所需要引入的头文件(可选)
#import <AdSupport/AdSupport.h>
#import <AppTrackingTransparency/AppTrackingTransparency.h>
此代码块在浮窗中显示
添加初始化代码
请将以下代码添加到 -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
// Optional
// 获取 IDFA
// 如需使用 IDFA 功能请添加此代码并在初始化方法的 advertisingIdentifier 参数中填写对应值
NSString *advertisingId;
if (@available(iOS 14, *)) {
[ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
if (status == ATTrackingManagerAuthorizationStatusAuthorized) {
advertisingId = [[ASIdentifierManager sharedManager] advertisingIdentifier].UUIDString;
}
}];
} else {
// 使用原方式访问 IDFA
advertisingId = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
}
JAdConfig *config = [[JAdConfig alloc] init];
config.appKey = @"your appkey";
config.advertisingId = advertisingId;
config.channel = @"App Store";
[JAdService setupWithConfig:config];
[JAdService setInMessageDelegate:self];
// Optional
// 获取 IDFA
// 如需使用 IDFA 功能请添加此代码并在初始化方法的 advertisingIdentifier 参数中填写对应值
NSString *advertisingId;
if (@available(iOS 14, *)) {
[ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
if (status == ATTrackingManagerAuthorizationStatusAuthorized) {
advertisingId = [[ASIdentifierManager sharedManager] advertisingIdentifier].UUIDString;
}
}];
} else {
// 使用原方式访问 IDFA
advertisingId = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
}
JAdConfig *config = [[JAdConfig alloc] init];
config.appKey = @"your appkey";
config.advertisingId = advertisingId;
config.channel = @"App Store";
[JAdService setupWithConfig:config];
[JAdService setInMessageDelegate:self];
此代码块在浮窗中显示
部分参数说明:
- appkey
- 开发者后台 》创建应用 》iOS》选择"消息推送"》配置BundleID。
- channel
- 指明应用程序包的下载渠道,为方便分渠道统计,具体值由你自行定义,如:App Store。
- advertisingId
- 获取的IDFA
成功运行
真机调试该项目,如果控制台输出以下日志则代表您已经集成成功。
2022-04-28 17:12:12.745823 219b28[1443:286814] | JIGUANG | I - [JIGUANG]
----- login result -----
uid:5460310207
registrationID:171976fa8a8620a14a4
2022-04-28 17:12:12.745823 219b28[1443:286814] | JIGUANG | I - [JIGUANG]
----- login result -----
uid:5460310207
registrationID:171976fa8a8620a14a4
此代码块在浮窗中显示
动态控制横幅广告展示页面接口
- 请正确配置currentViewControllerName:接口,该接口作用是在页面切换的时候调用,告诉sdk当前切换到的页面名称。
- 通过定向页面触发横幅广告下发的功能、黑白名单功能、横幅广告页面延迟展示功能都依赖于该接口调用。
- 请在页面切换的时候调用此方法。确保在所有页面的viewDidAppear中调用此方法。不然可能会造成inapp部分功能不完善。建议在viewController的基类中调用,或者使用method swizzling方法交换viewController的viewDidAppear方法。
接口定义
+ (void)currentViewControllerName:(NSString *)className;
+ (void)currentViewControllerName:(NSString *)className;
此代码块在浮窗中显示
参数说明
className:当前页面的类名,传空的话SDK会自动去获取最顶层vc的类名。
调用示例:
[JAdService currentViewControllerName:@"classname"];
[JAdService currentViewControllerName:@"classname"];
此代码块在浮窗中显示
文档内容是否对您有帮助?