【iOS】【项目全局动态埋点】Runtime+Aspects(hook)
2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>
1
2?
[錯(cuò)誤代碼示范]@interface UIViewController (Track) - (void)testTrack; - (void)handleTrack:(id)arg withSelector:(NSString*)sel withDict:(NSDictionary*)eventDict; @end@implementation UIViewController (Track) - (void)testTrack {NSLog(@"- (void)testTrack"); }- (void)handleTrack:(id)arg withSelector:(NSString*)sel withDict:(NSDictionary*)eventDict {NSLog(@"- (void)handleTrack");id<AspectInfo> aspectInfo = arg;NSLog(@"\n AspectHandlerBlock [%@]\n \n**-**", [[aspectInfo instance] class]);NSLog(@"\n AspectInfo originalInvocation<%@>, \n<%@>", aspectInfo.originalInvocation, aspectInfo.arguments);//特殊動(dòng)態(tài)處理,動(dòng)態(tài)獲取labelName || eventIDNSString * labelString = eventDict[TrackEvent_Label];NSString * idString = eventDict[TrackEvent_ID];if (eventDict[TrackEvent_Action]) {NSString * actionString = eventDict[TrackEvent_Action]; //!!!!!!!!!!注意在這錯(cuò)誤NSString * tmpString = [self valueForKey:actionString];NSDictionary * trackDict = @{eventDict[TrackEvent_Value]:tmpString};//!nilif (idString && labelString && trackDict) {NSLog(@"--TalkingData trackEvent--%@,%@,%@", idString, labelString, trackDict);}}else if (idString && labelString){NSLog(@"--TalkingData trackEvent--%@,%@", idString, labelString);} } @end文章參考:
http://objc-zen-book.books.yourtion.com/Chapter12/01-aspect-oriented-programming.html
http://www.jianshu.com/p/0497afdad36d#
http://tech.glowing.com/cn/method-swizzling-aop/
http://www.jianshu.com/p/69859d580354
http://www.bingjie.me/2015/11/05/OC%E4%B8%ADaspect%E5%88%87%E9%9D%A2%E7%BC%96%E7%A8%8B%E5%BA%94%E7%94%A8.html
對(duì)應(yīng)代碼參考:
https://github.com/weng1250/UserStatisticsWithRuntime
https://github.com/okcomp/AspectsDemo
https://github.com/steipete/Aspects
https://github.com/MikeFighting/LogByRunTime
?
轉(zhuǎn)載于:https://my.oschina.net/onepieceios/blog/744946
《新程序員》:云原生和全面數(shù)字化實(shí)踐50位技術(shù)專(zhuān)家共同創(chuàng)作,文字、視頻、音頻交互閱讀總結(jié)
以上是生活随笔為你收集整理的【iOS】【项目全局动态埋点】Runtime+Aspects(hook)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 基于CentOS 6.8平台最新源代码包
- 下一篇: tomcat、腾讯云主机和微信