Commit 588044f0 authored by 汪洋's avatar 汪洋

Merge branch 'dev' into 'master'

Dev



See merge request !11
parents 6e44d469 fbd442d8
......@@ -94,7 +94,15 @@ static NSString *sdkVersion = @"110";
- (void)handleEventDeviceOpened{
WMCacheService *cache = [WMCacheService sharedInstance];
/** 每次打开APP埋点 **/
[Phobos track:@"device_opened" attributes:@{} sendNow:YES];
NSDictionary *dict = @{@"build_cpu_abi": [PhobosUtil currentDeviceCPUType],
@"cpu_count": [PhobosUtil currentDeviceCPUCount],
@"mac_address": [PhobosUtil getMacAddress],
@"phone_operator": [PhobosUtil getTelephonyInfo],
@"total_memory": [PhobosUtil getTotalMemorySize],
@"run_time": [PhobosUtil deviceRunTime],
@"uuid": [PhobosUtil deviceId],
};
[Phobos track:@"device_opened" attributes:dict sendNow:YES];
/** 第一次打开APP埋点 **/
if (![cache fetchObjectAtDiskWithkey:PhobosHaveOpenApp]) {
......@@ -149,8 +157,6 @@ static NSString *sdkVersion = @"110";
/**
* @brief 应用打开时的处理
*
* @param sender
*
* @since 0.0.1
*/
- (void)handleAppFinishLaunch:(id)sender{
......@@ -162,8 +168,6 @@ static NSString *sdkVersion = @"110";
/**
* @brief 应用进入前台的处理
*
* @param sender
*
* @since 0.0.1
*/
- (void)handleAppInForeground:(id)sender{
......@@ -176,9 +180,6 @@ static NSString *sdkVersion = @"110";
/**
* @brief 应用进入后台的处理
*
* @param sender
*
* @since 0.0.1
*/
- (void)handleAppInBackgound:(id)sender{
......@@ -203,7 +204,15 @@ static NSString *sdkVersion = @"110";
NSDate *date = [NSDate date];
double endTime = [date timeIntervalSince1970];
NSString *usedTime = [NSString stringWithFormat:@"%ld",(long)(endTime - beginTime)];
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObjectsAndKeys:usedTime,@"duration",nil];
NSDictionary *dict = @{@"duration":usedTime,
@"build_cpu_abi": [PhobosUtil currentDeviceCPUType],
@"cpu_count": [PhobosUtil currentDeviceCPUCount],
@"mac_address": [PhobosUtil getMacAddress],
@"phone_operator": [PhobosUtil getTelephonyInfo],
@"total_memory": [PhobosUtil getTotalMemorySize],
@"run_time": [PhobosUtil deviceRunTime],
@"uuid": [PhobosUtil deviceId],
};
[Phobos track:@"on_app_session_over" attributes:dict];
[cache removeObjectAtDiskWithkey:PhobosBeginTime];
//当前session结束之后,把id置为0
......@@ -331,8 +340,6 @@ static NSString *sdkVersion = @"110";
/**
* @brief 将埋点时间封装成词典数据
*
* @return
*
* @since 0.0.1
*/
- (NSDictionary *)prepareDictionaryForEvent:(NSString *)eventId attributes:(NSDictionary *)attributes{
......@@ -434,7 +441,7 @@ static NSString *sdkVersion = @"110";
让sendArray方法负责发送,数据一旦转移到缓存区,就把原有的数据干掉。
@author zhaiguojun 16-10-17 in (null)
@param array 参数
@param now 是否立即清楚缓存
@param clean 是否立即清楚缓存
*/
- (void)sendArray:(NSArray *)array cleanCacheRightNow:(BOOL)clean {
@try {
......
......@@ -41,4 +41,39 @@ typedef void (^SendDataSuccessBlock)(NSInteger code);
* 获取IP地址
*/
+ (NSString *)getIPAddress:(BOOL)preferIPv4;
/**
* 获取cup指令集
*/
+ (NSString *)currentDeviceCPUType;
/***
* CPU总数目
**/
+ (NSString *)currentDeviceCPUCount;
/***
* 网卡地址
**/
+ (NSString *)getMacAddress;
/**
* 获取运营商信息
*/
+ (NSString *)getTelephonyInfo;
/**
* 内存大小,单位:兆
*/
+ (NSString *)getTotalMemorySize;
/**
* 获取手机运行时间,从开机到现在
*/
+ (NSString *)deviceRunTime;
@end
......@@ -13,6 +13,13 @@
#import <ifaddrs.h>
#import <arpa/inet.h>
#import <net/if.h>
#import <net/if_dl.h>
#import <CoreTelephony/CTCarrier.h>
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
#import <sys/types.h>
#import <sys/sysctl.h>
#import <mach/machine.h>
#import "sys/utsname.h"
#import "Phobos.h"
#define IOS_CELLULAR @"pdp_ip0"
......@@ -230,10 +237,6 @@
NSTextCheckingResult *firstMatch=[regex firstMatchInString:ipAddress options:0 range:NSMakeRange(0, [ipAddress length])];
if (firstMatch) {
// NSRange resultRange = [firstMatch rangeAtIndex:0];
// NSString *result=[ipAddress substringWithRange:resultRange];
// //输出结果
// NSLog(@"%@",result);
return YES;
}
}
......@@ -278,4 +281,134 @@
return [addresses count] ? addresses : nil;
}
/**
* 这里就叫做CPU指令集吧,目前主要采集这四种,armv6、armv7、armv7s、arm64
*/
+ (NSString *)currentDeviceCPUType {
NSMutableString *cpuType = [[NSMutableString alloc] init];
size_t size;
cpu_type_t type;
cpu_subtype_t subtype;
size = sizeof(type);
sysctlbyname("hw.cputype", &type, &size, NULL, 0);
size = sizeof(subtype);
sysctlbyname("hw.cpusubtype", &subtype, &size, NULL, 0);
if (type == CPU_TYPE_X86) {
[cpuType appendString:@"x86"];
} else if (type == CPU_TYPE_ARM) {
[cpuType appendString:@"ARM"];
switch(subtype) {
case CPU_SUBTYPE_ARM_V6:
[cpuType appendString:@"V6"];
break;
case CPU_SUBTYPE_ARM_V7:
[cpuType appendString:@"V7"];
break;
case CPU_SUBTYPE_ARM_V7S:
[cpuType appendString:@"V7s"];
break;
}
} else if (type == CPU_TYPE_ARM64) {
[cpuType appendString:@"ARM64"];
} else {
// 暂时不采集其他的
[cpuType appendString:@"nuknow type"];
}
return cpuType;
}
/***
* CPU总数目
**/
+ (NSString *)currentDeviceCPUCount {
NSInteger count = [NSProcessInfo processInfo].activeProcessorCount;
return [NSString stringWithFormat:@"%ld", (long)count];
}
/***
* 网卡地址
**/
+ (NSString *)getMacAddress {
int mib[6];
size_t len;
char *buf;
unsigned char *ptr;
struct if_msghdr *ifm;
struct sockaddr_dl *sdl;
mib[0] = CTL_NET;
mib[1] = AF_ROUTE;
mib[2] = 0;
mib[3] = AF_LINK;
mib[4] = NET_RT_IFLIST;
if ((mib[5] = if_nametoindex("en0")) == 0) {
printf("Error: if_nametoindex error/n");
return NULL;
}
if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0) {
printf("Error: sysctl, take 1/n");
return NULL;
}
if ((buf = malloc(len)) == NULL) {
printf("Could not allocate memory. error!/n");
return NULL;
}
if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) {
printf("Error: sysctl, take 2");
return NULL;
}
ifm = (struct if_msghdr *)buf;
sdl = (struct sockaddr_dl *)(ifm + 1);
ptr = (unsigned char *)LLADDR(sdl);
NSString *outstring = [NSString stringWithFormat:@"%02x%02x%02x%02x%02x%02x", *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), *(ptr+5)];
free(buf);
return [outstring uppercaseString];
}
/**
* 获取运营商信息
*/
+ (NSString *)getTelephonyInfo {
CTTelephonyNetworkInfo *info = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier *carrier = [info subscriberCellularProvider];
if (carrier == nil) {
return @"";
}
return [carrier carrierName] != nil ? [carrier carrierName] : @"";
}
/**
* 内存大小,单位:兆
*/
+ (NSString *)getTotalMemorySize {
unsigned long long resultSize = [NSProcessInfo processInfo].physicalMemory/1024/1024;
return [NSString stringWithFormat:@"%llu", resultSize];
}
/**
* 获取手机运行时间,从开机到现在
*/
+ (NSString *)deviceRunTime {
struct timeval boottime;
int mib[2] = {CTL_KERN, KERN_BOOTTIME};
size_t size = sizeof(boottime);
time_t now;
time_t uptime = -1;//默认为没有使用吧
(void)time(&now);
if (sysctl(mib, 2, &boottime, &size, NULL, 0) != -1 && boottime.tv_sec != 0) {
uptime = now - boottime.tv_sec;
}
return [NSString stringWithFormat:@"%ld", uptime];
}
@end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment