轉(zhuǎn)載請附原文鏈接:http://blog.fandong.me/2017/07/18/iOS-AliAnalitics/
集成阿里云移動數(shù)據(jù)分析
1.集成移動數(shù)據(jù)分析SDK后與支付寶SDK發(fā)生符號沖突
https://help.aliyun.com/knowledge_detail/39075.html
2.統(tǒng)計頁面進入事件
每個頁面都需要統(tǒng)計,對于一個項目來說工作量不小,我們可以利用Runtime里的方法替換來完成所有頁面的統(tǒng)計
新建類別
UIViewController+MYExtension
#import "UIViewController+MYExtension.h"
#import <AlicloudMobileAnalitics/ALBBMAN.h>
#define AliAnalitics [ALBBMANPageHitHelper getInstance]
@implementation UIViewController (MYExtension)
- (void)my_viewDidAppear:(BOOL)animated{
[AliAnalitics pageAppear:self];
[self my_viewDidAppear:animated];
}
- (void)my_viewDidDisappear:(BOOL)animated{
[AliAnalitics pageDisAppear:self];
[self my_viewDidDisappear:animated];
}
+ (void)load{
NSString *className = NSStringFromClass(self.class);
MYLog(@"%@",className);
static dispatch_once_t onceToken;
dispatch_once(&onceToken,^{
[UIViewController replaceOrExchangeMethodOriginSelector:@selector(viewDidAppear:) SwizzledSelector:@selector(my_viewDidAppear:)];
[UIViewController replaceOrExchangeMethodOriginSelector:@selector(viewDidDisappear:) SwizzledSelector:@selector(my_viewDidDisappear:)];
});
}
+ (void)replaceOrExchangeMethodOriginSelector:(SEL)originSelector SwizzledSelector:(SEL)swizzledSelector{
Class class=[self class];
Method originalMethod = class_getInstanceMethod(class,originSelector);
Method swizzledMethod = class_getInstanceMethod(class,swizzledSelector);
BOOL didAddMethod =
class_addMethod(class,
originSelector,
method_getImplementation(swizzledMethod),
method_getTypeEncoding(swizzledMethod));
if(didAddMethod){
class_replaceMethod(class,
swizzledSelector,
method_getImplementation(originalMethod),
method_getTypeEncoding(originalMethod));
}else{
method_exchangeImplementations(originalMethod,swizzledMethod);
}
}