标签:
1.首先在友盟平台添加新应用中,申请一个新应用,然后得到一个appkey.
2.下载ios平台的sdk文件,将以下两个文件拖入工程中。
(1)libMobClickLibrary.a
(2)MobClick.h
3.添加类库:
TARGETS-->Build Phases-->Link Binary With Libraries--> + -->libz.dylib (Xcode7请选择libz.tbd)
如过使用cocopod添加,可用:(pod ‘UMengAnalytics‘)。
4.实现相关方法:
#import <Foundation/Foundation.h> @interface StateCollect : NSObject + (void)setup; + (void)intoPage:(NSString *)pageName; + (void)outPage:(NSString *)pageName; + (void)event:(NSString *)event value:(NSString *)value; @end
#import "StateCollect.h" #import "MobClick.h" #define ChannelEnterprise @"Enterprise" @implementation StateCollect #define UMengKey @"" + (void)setup { NSString *chanel = ChannelEnterprise; #ifdef APPSTORE chanel = ChannelAppStore; #endif [MobClick startWithAppkey:UMengKey reportPolicy:REALTIME channelId:chanel]; } + (void)intoPage:(NSString *)pageName { [MobClick beginLogPageView:pageName]; } + (void)outPage:(NSString *)pageName { [MobClick endLogPageView:pageName]; } + (void)event:(NSString *)event value:(NSString *)value { [MobClick event:event label:value]; }
5.在appdelegate中建立链接:
[StateCollect setup];
注:StateCollect为我建立的NSObject页面
6.在统计界面加入调用统计的方法:
-(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [StateCollect intoPage:NSStringFromClass([self class])]; } -(void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [StateCollect outPage:NSStringFromClass([self class])]; }
7.如果你在友盟的我的应用程序中,添加了相关事件的统计,可调用这个方法来进行统计:
[StateCollect event:@"Login" value:NSStringFromClass([self class])];
注:Login为我在设置的相关事件。
8.如果你是第一次使用友盟,那你需要在:我的产品->设置->应用信息中,开启使用:
完成以上设置后,运行程序,发现以下错误:
"_compress2", referenced from: +[UMANUtil deflatedDataPrefixedWith:level:source:] in libMobClickLibrary.a(UMANUtil.o) ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
可以通过设置Other Linker Flag的值未-lz来解决。
标签:
原文地址:http://www.cnblogs.com/moxuexiaotong/p/4876130.html