Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
GMPhobos
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gengmeiios
GMPhobos
Commits
6cf2972e
Commit
6cf2972e
authored
Sep 05, 2017
by
翟国钧
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加设备基础信息,
parent
4472a7d0
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
190 additions
and
6 deletions
+190
-6
Phobos.m
Pod/Classes/Phobos.m
+18
-2
PhobosUtil.h
Pod/Classes/PhobosUtil.h
+35
-0
PhobosUtil.m
Pod/Classes/PhobosUtil.m
+137
-4
No files found.
Pod/Classes/Phobos.m
View file @
6cf2972e
...
@@ -93,7 +93,15 @@ static NSString *sdkVersion = @"110";
...
@@ -93,7 +93,15 @@ static NSString *sdkVersion = @"110";
-
(
void
)
handleEventDeviceOpened
{
-
(
void
)
handleEventDeviceOpened
{
WMCacheService
*
cache
=
[
WMCacheService
sharedInstance
];
WMCacheService
*
cache
=
[
WMCacheService
sharedInstance
];
/** 每次打开APP埋点 **/
/** 每次打开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埋点 **/
/** 第一次打开APP埋点 **/
if
(
!
[
cache
fetchObjectAtDiskWithkey
:
PhobosHaveOpenApp
])
{
if
(
!
[
cache
fetchObjectAtDiskWithkey
:
PhobosHaveOpenApp
])
{
...
@@ -202,7 +210,15 @@ static NSString *sdkVersion = @"110";
...
@@ -202,7 +210,15 @@ static NSString *sdkVersion = @"110";
NSDate
*
date
=
[
NSDate
date
];
NSDate
*
date
=
[
NSDate
date
];
double
endTime
=
[
date
timeIntervalSince1970
];
double
endTime
=
[
date
timeIntervalSince1970
];
NSString
*
usedTime
=
[
NSString
stringWithFormat
:
@"%ld"
,(
long
)(
endTime
-
beginTime
)];
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
];
[
Phobos
track
:
@"on_app_session_over"
attributes
:
dict
];
[
cache
removeObjectAtDiskWithkey
:
PhobosBeginTime
];
[
cache
removeObjectAtDiskWithkey
:
PhobosBeginTime
];
//当前session结束之后,把id置为0
//当前session结束之后,把id置为0
...
...
Pod/Classes/PhobosUtil.h
View file @
6cf2972e
...
@@ -41,4 +41,39 @@ typedef void (^SendDataSuccessBlock)(NSInteger code);
...
@@ -41,4 +41,39 @@ typedef void (^SendDataSuccessBlock)(NSInteger code);
* 获取IP地址
* 获取IP地址
*/
*/
+
(
NSString
*
)
getIPAddress
:(
BOOL
)
preferIPv4
;
+
(
NSString
*
)
getIPAddress
:(
BOOL
)
preferIPv4
;
/**
* 获取cup指令集
*/
+
(
NSString
*
)
currentDeviceCPUType
;
/***
* CPU总数目
**/
+
(
NSString
*
)
currentDeviceCPUCount
;
/***
* 网卡地址
**/
+
(
NSString
*
)
getMacAddress
;
/**
* 获取运营商信息
*/
+
(
NSString
*
)
getTelephonyInfo
;
/**
* 内存大小,单位:兆
*/
+
(
NSString
*
)
getTotalMemorySize
;
/**
* 获取手机运行时间,从开机到现在
*/
+
(
NSString
*
)
deviceRunTime
;
@end
@end
Pod/Classes/PhobosUtil.m
View file @
6cf2972e
...
@@ -13,6 +13,13 @@
...
@@ -13,6 +13,13 @@
#import <ifaddrs.h>
#import <ifaddrs.h>
#import <arpa/inet.h>
#import <arpa/inet.h>
#import <net/if.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"
#define IOS_CELLULAR @"pdp_ip0"
#define IOS_CELLULAR @"pdp_ip0"
#define IOS_WIFI @"en0"
#define IOS_WIFI @"en0"
...
@@ -236,10 +243,6 @@
...
@@ -236,10 +243,6 @@
NSTextCheckingResult
*
firstMatch
=
[
regex
firstMatchInString
:
ipAddress
options
:
0
range
:
NSMakeRange
(
0
,
[
ipAddress
length
])];
NSTextCheckingResult
*
firstMatch
=
[
regex
firstMatchInString
:
ipAddress
options
:
0
range
:
NSMakeRange
(
0
,
[
ipAddress
length
])];
if
(
firstMatch
)
{
if
(
firstMatch
)
{
// NSRange resultRange = [firstMatch rangeAtIndex:0];
// NSString *result=[ipAddress substringWithRange:resultRange];
// //输出结果
// NSLog(@"%@",result);
return
YES
;
return
YES
;
}
}
}
}
...
@@ -284,4 +287,134 @@
...
@@ -284,4 +287,134 @@
return
[
addresses
count
]
?
addresses
:
nil
;
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
];
NSString
*
mCarrier
=
[
NSString
stringWithFormat
:
@"%@"
,[
carrier
carrierName
]];
return
mCarrier
;
}
/**
* 内存大小,单位:兆
*/
+
(
NSString
*
)
getTotalMemorySize
{
double
resultSize
=
[
NSProcessInfo
processInfo
].
physicalMemory
/
1024
/
1024
;
return
[
NSString
stringWithFormat
:
@"%f"
,
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
@end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment