1. 导入SDK
1.1 CocoaPods导入SDK
执行如下命令查询ptengine 相关SDK。
pod setup //更新本地仓库
pod search ptevent //查询ptengine所有SDK
- pod setup //更新本地仓库
- pod search ptevent //查询ptengine所有SDK
pod setup //更新本地仓库
pod search ptevent //查询ptengine所有SDK
运行结果如下图:

在本地的Podfile文件中加入相关SDK导入如下指令然后install即可:
pod 'PtEvent', '~>1.0.0'
- pod 'PtEvent', '~>1.0.0'
pod 'PtEvent', '~>1.0.0'
最后在app工程中要加入如下配置,以保证当前工程中能够从Pod工程中自动继承SDK相关依赖库,并在Other Linker Flag配置项中添加-ObjC
1.2 手动导入SDK
我们提供了两种不同的方式将SDK导入到应用中,您可以选择适合你的方式进行导入。
1.2.1 拖拽导入
直接拖拽下载下来的相关SDK到App工程中的Frameworks目录下,并选中”Copy item if needed”,点击Finish,以保证SDK拷贝到当前工程目录中,如图:

1.2.2 右键导入
选中App工程中的Frameworks文件夹或者工程文件,右键菜单选择”Add Files to ‘demo.project’””, 以保证SDK拷贝到当前工程目录
中,如图:

2. 添加依赖框架
在App -> TARGETS -> Build Phases 配置项中通过+号加入图示中的依赖框架,并在Other Linker Flag配置项中添加-ObjC:
3. 配置 App Id 和 渠道
当app启动时,需要先通过SDK接口注册appKey,此方法必须调用:
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[PtAgent sharedInstance] PTStartWithAppKey:@"**********" channel:**];
}
- -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
- [[PtAgent sharedInstance] PTStartWithAppKey:@"**********" channel:**];
- }
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[PtAgent sharedInstance] PTStartWithAppKey:@"**********" channel:**];
}
请确保该方法在application didFinishLaunchingWithOptions:的第一行处调用,已确保在程序启动时要加载的所有ViewController都被成功监听。
AppKey:为后台创建应用后生成的key值,不能为空, 此处可替换为相应的值。
channel:为app发布的渠道名称,如果传nil, 则使用默认值“AppStore”, 如果app要发布到其他渠道,请填写相关渠道名称。
4. 代码示例
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[PtAgent sharedInstance] PTStartWithAppKey:@"fee5d1f7407c0756" channel:nil];
[[PtAgent sharedInstance] PTSetAllLevelLogEnabled:YES];
[[PtAgent sharedInstance] PTSetLogEnabled:NO forLevel:LogLevelDebug];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.rootViewController = [SDAppFrameTabBarController new];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
[self setupNavBar];
return YES;
}
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
-
- [[PtAgent sharedInstance] PTStartWithAppKey:@"fee5d1f7407c0756" channel:nil];
- [[PtAgent sharedInstance] PTSetAllLevelLogEnabled:YES];
- [[PtAgent sharedInstance] PTSetLogEnabled:NO forLevel:LogLevelDebug];
-
- self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
- self.window.rootViewController = [SDAppFrameTabBarController new];
- self.window.backgroundColor = [UIColor whiteColor];
- [self.window makeKeyAndVisible];
-
- [self setupNavBar];
- return YES;
- }
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[PtAgent sharedInstance] PTStartWithAppKey:@"fee5d1f7407c0756" channel:nil];
[[PtAgent sharedInstance] PTSetAllLevelLogEnabled:YES];
[[PtAgent sharedInstance] PTSetLogEnabled:NO forLevel:LogLevelDebug];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.rootViewController = [SDAppFrameTabBarController new];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
[self setupNavBar];
return YES;
}
5. 图形化自定义变量
如果App中有自定义Label, 并重写了- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event方法,则会导致PtEventSDK中UILabel(Category)中的hitTest方法无法调用,此时需要开发者在重写的hitTest方法中注册一个响应方法,以保证SDK内部方法正确调用:
@implementation AppTestLabel
//如果App中有自定义Label, 并重写了hitTest方法,会导致SDK中UILabel(Category)中的hitTest方法无法调用
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
[super hitTest:point withEvent:event];
[[PtAgent sharedInstance]PTRegisterHitTestResponseForUILabel:point withEvent:event withCurrentLabelObject:self];
return nil;
}
@end
- @implementation AppTestLabel
- //如果App中有自定义Label, 并重写了hitTest方法,会导致SDK中UILabel(Category)中的hitTest方法无法调用
- - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
- [super hitTest:point withEvent:event];
- [[PtAgent sharedInstance]PTRegisterHitTestResponseForUILabel:point withEvent:event withCurrentLabelObject:self];
- return nil;
- }
- @end
@implementation AppTestLabel
//如果App中有自定义Label, 并重写了hitTest方法,会导致SDK中UILabel(Category)中的hitTest方法无法调用
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
[super hitTest:point withEvent:event];
[[PtAgent sharedInstance]PTRegisterHitTestResponseForUILabel:point withEvent:event withCurrentLabelObject:self];
return nil;
}
@end