Commit 534b3740 authored by 翟国钧's avatar 翟国钧

在所有埋点数据的device字段中增加IP地址

parent e8223434
......@@ -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",
......
......@@ -37,4 +37,8 @@ typedef void (^SendDataSuccessBlock)(NSInteger code);
+ (BOOL)isNonEmpty:(NSString *)string;
+ (NSData *)encodeJSON:(id)obj;
+ (NSString *)deviceId;
/**
* 获取IP地址
*/
+ (NSString *)getIPAddress;
@end
......@@ -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
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