forked from PhillyOpen/Cycle-Philly-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UIDevice+IdentifierAddition.m
101 lines (91 loc) · 2.83 KB
/
UIDevice+IdentifierAddition.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//
// UIDevice(Identifier).m
// UIDeviceAddition
//
// Created by Georg Kitz on 20.08.11.
// Copyright 2011 Aurora Apps. All rights reserved.
//
#import "UIDevice+IdentifierAddition.h"
#import "NSString+MD5Addition.h"
#include <sys/socket.h> // Per msqr
#include <sys/sysctl.h>
#include <net/if.h>
#include <net/if_dl.h>
//@interface UIDevice(Private)
//
//- (NSString *) macaddress;
//
//@end
//
//@implementation UIDevice (IdentifierAddition)
@implementation UIDevice (advertisingIdentifier)
////////////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark Private Methods
// Return the local MAC addy
// Courtesy of FreeBSD hackers email list
// Accidentally munged during previous update. Fixed thanks to erica sadun & mlamb.
//- (NSString *) macaddress{
//
// 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 *outstring = [NSString stringWithFormat:@"%02X:%02X:%02X:%02X:%02X:%02X",
// *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), *(ptr+5)];
// free(buf);
//
// return outstring;
//}
////////////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark Public Methods
- (NSString *) uniqueDeviceIdentifier{
// NSString *macaddress = [[UIDevice currentDevice] macaddress];
// NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
//
// NSString *stringToHash = [NSString stringWithFormat:@"%@%@",macaddress,bundleIdentifier];
// NSString *uniqueIdentifier = [stringToHash stringFromMD5];
NSString *uniqueIdentifier =[[[UIDevice currentDevice] identifierForVendor] UUIDString];
return uniqueIdentifier;
}
//- (NSString *) uniqueGlobalDeviceIdentifier{
// NSString *macaddress = [[UIDevice currentDevice] macaddress];
// NSString *uniqueIdentifier = [macaddress stringFromMD5];
//
// return uniqueIdentifier;
//}
@end