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
534b3740
Commit
534b3740
authored
Aug 18, 2017
by
翟国钧
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
在所有埋点数据的device字段中增加IP地址
parent
e8223434
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
1 deletion
+34
-1
Phobos.m
Pod/Classes/Phobos.m
+2
-1
PhobosUtil.h
Pod/Classes/PhobosUtil.h
+4
-0
PhobosUtil.m
Pod/Classes/PhobosUtil.m
+28
-0
No files found.
Pod/Classes/Phobos.m
View file @
534b3740
...
...
@@ -347,7 +347,8 @@ static NSString *sdkVersion = @"110";
@"Apple"
,
@"manufacturer"
,
@
(
self
.
gps
.
coordinate
.
latitude
),
@"lat"
,
@
(
self
.
gps
.
coordinate
.
longitude
),
@"lng"
,
_netStatus
,
@"is_WiFi"
,
nil
];
_netStatus
,
@"is_WiFi"
,
[
PhobosUtil
getIPAddress
],
@"ip"
,
nil
];
NSMutableDictionary
*
appParams
=
[
NSMutableDictionary
dictionaryWithObjectsAndKeys
:
self
.
appName
,
@"name"
,
self
.
appVersion
,
@"version"
,
...
...
Pod/Classes/PhobosUtil.h
View file @
534b3740
...
...
@@ -37,4 +37,8 @@ typedef void (^SendDataSuccessBlock)(NSInteger code);
+
(
BOOL
)
isNonEmpty
:(
NSString
*
)
string
;
+
(
NSData
*
)
encodeJSON
:(
id
)
obj
;
+
(
NSString
*
)
deviceId
;
/**
* 获取IP地址
*/
+
(
NSString
*
)
getIPAddress
;
@end
Pod/Classes/PhobosUtil.m
View file @
534b3740
...
...
@@ -10,6 +10,8 @@
#import <zlib.h>
#import "PhobosConfig.h"
#import <AdSupport/AdSupport.h>
#import <ifaddrs.h>
#import <arpa/inet.h>
@implementation
PhobosUtil
...
...
@@ -194,4 +196,30 @@
return
idfv
;
}
+
(
NSString
*
)
getIPAddress
{
NSString
*
address
=
@""
;
struct
ifaddrs
*
interfaces
=
NULL
;
struct
ifaddrs
*
temp_addr
=
NULL
;
int
success
=
0
;
// retrieve the current interfaces - returns 0 on success
success
=
getifaddrs
(
&
interfaces
);
if
(
success
==
0
)
{
// Loop through linked list of interfaces
temp_addr
=
interfaces
;
while
(
temp_addr
!=
NULL
)
{
if
(
temp_addr
->
ifa_addr
->
sa_family
==
AF_INET
)
{
// Check if interface is en0 which is the wifi connection on the iPhone
if
([[
NSString
stringWithUTF8String
:
temp_addr
->
ifa_name
]
isEqualToString
:
@"en0"
])
{
// Get NSString from C String
address
=
[
NSString
stringWithUTF8String
:
inet_ntoa
(((
struct
sockaddr_in
*
)
temp_addr
->
ifa_addr
)
->
sin_addr
)];
}
}
temp_addr
=
temp_addr
->
ifa_next
;
}
}
// Free memory
freeifaddrs
(
interfaces
);
return
address
;
}
@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