NSString * AppKey = @ "57105bbbe0f55a7938002063"; NSString * devicename = [[[Uidevice Currentdevice] name] stringbyaddingpercentescapesusingencoding: Nsutf8stringencoding]; NSString * mac = [self macstring]; NSString * IDFA = [self idfastring]; NSString * IDFV = [self idfvstring]; NSString * urlstring = [NSString stringwithformat:@ "http://log.umtrack.com/ping/%@/?devicename=%@&mac=%@& idfa=%@&idfv=%@ ", AppKey, DeviceName, Mac, IDFA, IDFV]; [Nsurlconnection connectionwithrequest:[nsurlrequest requestwithurl: [Nsurl urlwithstring:urlstring]] Delegate:nil] ;
#include <sys/socket.h> #include <sys/sysctl.h> #include <net/if.h> #include <net/if_dl.h>// For Idfa#import <adsupport/adsupport.h>-(NSString *) macstring{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"); Free (BUF); return NULL; IFM = (struct IF_MSGHDR *) buf; SDL = (struct SOCKADDR_DL *) (IFM + 1); PTR = (UNSigned char *) LLADDR (SDL); NSString *macstring = [NSString stringwithformat:@ "%02x:%02x:%02x:%02x:%02x:%02x", *ptr, * (ptr+1), * (ptr+2), * (ptr+ 3), * (PTR+4), * (ptr+5)]; Free (BUF); return macstring;} -(NSString *) idfastring {nsbundle *adsupportbundle = [NSBundle bundlewithpath:@]/system/library/frameworks/adsupport . Framework "]; [Adsupportbundle load]; if (Adsupportbundle = = nil) {return @ ""; } else{Class Asidentifiermclass = nsclassfromstring (@ "Asidentifiermanager"); if (Asidentifiermclass = = nil) {return @ ""; } else{//for no arc//asidentifiermanager *asim = [[[Asidentifiermclass alloc] init] Autorel Ease]; For arc Asidentifiermanager *asim = [[Asidentifiermclass alloc] init]; if (AsIM = = nil) {return @ ""; } else{if (asim.advertisingtrackingenabled) {return [Asim.advertisingidentifi ER Uuidstring]; } else{return [Asim.advertisingidentifier uuidstring]; }}}}}-(NSString *) idfvstring{if ([[Uidevice Currentdevice] Respondstoselector: @selector (ident Ifierforvendor)] {return [[Uidevice Currentdevice].identifierforvendor uuidstring]; } return @ "";}
Umeng Track related