Wow... look at all the "panic stories" online this week regarding using an iPhone's UDID.
哇...本周在线查看关于使用iPhone的UDID的所有“恐慌故事”。
[[UIDevice currentDevice] uniqueIdentifier]
What SHOULD we be using instead?
我们应该使用什么呢?
What if the phone is sold to another user... and an app has stored some data on a remote server, based on the phone's UDID?
如果手机被卖给另一个用户......并且应用程序已根据手机的UDID在远程服务器上存储了一些数据,该怎么办?
(Of course, I want to avoid the problems with the app store's "encryption restrictions".)
(当然,我想避免应用商店的“加密限制”问题。)
7 个解决方案
#1
3
Why not use the Mac Address and possibly then hash it up.
为什么不使用Mac地址,然后可能将其哈希。
There is an excellent UIDevice-Extension Category here
这里有一个很棒的UIDevice-Extension类别
- (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");
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)];
// 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;
}
You could possibly hash this with the model?
你可以用模型散列这个吗?
#2
2
As I asked this morning in this post, there are some alternative :
正如我今天早上在这篇文章中提到的,还有一些选择:
1- first, as Apple recommands, identify per install instead of indentifying per device. Therefore, you can use CFUUIDRef. Example :
1-首先,正如Apple推荐的那样,确定每次安装而不是识别每个设备。因此,您可以使用CFUUIDRef。示例:
NSString *uuid = nil;
CFUUIDRef theUUID = CFUUIDCreate(kCFAllocatorDefault);
if (theUUID) {
uuid = NSMakeCollectable(CFUUIDCreateString(kCFAllocatorDefault, theUUID));
[uuid autorelease];
CFRelease(theUUID);
}
2- If you care about a worldwide unique identifier, so you could store this identifier on iCloud.
2-如果您关心全球唯一标识符,则可以将此标识符存储在iCloud上。
3- At last, if you really need an identifier that remains after app re-install (that not occurs so frequently), you can use Keychains (Apple's keychain doc). But will apple team like it ?
3-最后,如果你真的需要一个在重新安装app之后仍然存在的标识符(不经常发生),你可以使用Keychains(Apple的keychain doc)。但苹果团队会喜欢吗?
#3
1
UUID is just depreciated and so will be around for a while, Apple have not said much about this depreciation much yet, I would wait until they have more to say about this and maybe the will offer some alternative.
UUID只是贬值,因此将会出现一段时间,Apple还没有多说这种折旧,我会等到他们对此有更多的说法,也许会提供一些替代方案。
#4
1
Like this:
@interface UIDevice (UIDeviceAppIdentifier)
@property (readonly) NSString *deviceApplicationIdentifier;
@end
@implementation UIDevice (UIDeviceAppIdentifier)
- (NSString *) deviceApplicationIdentifier
{
static NSString *name = @"theDeviceApplicationIdentifier";
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *value = [defaults objectForKey: name];
if (!value)
{
value = (NSString *) CFUUIDCreateString (NULL, CFUUIDCreate(NULL));
[defaults setObject: value forKey: name];
[defaults synchronize];
}
return value;
}
@end
the iOS documentation more or less describes use of CFUUIDCreate() to create an identifier and suggests using UserDefaults to store it.
iOS文档或多或少地描述了使用CFUUIDCreate()来创建标识符并建议使用UserDefaults来存储它。
#5
0
The recommended way is by using UUID generation, and associate that with something that the user him/herself is willing to provide to the app.
推荐的方法是使用UUID生成,并将其与用户自己愿意为应用程序提供的内容相关联。
Then, store this data externally, where it could be retrieved again. There are probably other ways to do this easily, but this is the recommended way.
然后,将此数据存储在外部,以便再次检索。可能有其他方法可以轻松完成此操作,但这是推荐的方法。
#6
0
One solution would be to have the application issue a free in-app purchase.
一种解决方案是让应用程序发布免费的应用内购买。
This purchase would be:
此次购买将是:
-
Trackable, with a unique number (purchase) number which would be meaningful only to your app.
可追踪,具有唯一编号(购买)编号,仅对您的应用有意义。
-
Movable, if the person switches devices
如果人员切换设备,则可移动
-
Retrievable, if the app is deleted (or the phone is wiped and reloaded) - the In-App purchases can be restored.
可检索,如果应用程序被删除(或手机被擦除并重新加载) - 可以恢复应用程序内购买。
#7
0
Apple's documentation says:
Apple的文档说:
"Do not use the uniqueIdentifier property. To create a unique identifier specific to your app, you can call the CFUUIDCreate function to create a UUID, and write it to the defaults database using the NSUserDefaults class."
“不要使用uniqueIdentifier属性。要创建特定于应用程序的唯一标识符,可以调用CFUUIDCreate函数创建UUID,并使用NSUserDefaults类将其写入默认数据库。”
Here's a quick snippet:
这是一个快速片段:
CFUUIDRef udid = CFUUIDCreate(NULL);
NSString *udidString = (NSString *) CFUUIDCreateString(NULL, udid);
#1
3
Why not use the Mac Address and possibly then hash it up.
为什么不使用Mac地址,然后可能将其哈希。
There is an excellent UIDevice-Extension Category here
这里有一个很棒的UIDevice-Extension类别
- (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");
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)];
// 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;
}
You could possibly hash this with the model?
你可以用模型散列这个吗?
#2
2
As I asked this morning in this post, there are some alternative :
正如我今天早上在这篇文章中提到的,还有一些选择:
1- first, as Apple recommands, identify per install instead of indentifying per device. Therefore, you can use CFUUIDRef. Example :
1-首先,正如Apple推荐的那样,确定每次安装而不是识别每个设备。因此,您可以使用CFUUIDRef。示例:
NSString *uuid = nil;
CFUUIDRef theUUID = CFUUIDCreate(kCFAllocatorDefault);
if (theUUID) {
uuid = NSMakeCollectable(CFUUIDCreateString(kCFAllocatorDefault, theUUID));
[uuid autorelease];
CFRelease(theUUID);
}
2- If you care about a worldwide unique identifier, so you could store this identifier on iCloud.
2-如果您关心全球唯一标识符,则可以将此标识符存储在iCloud上。
3- At last, if you really need an identifier that remains after app re-install (that not occurs so frequently), you can use Keychains (Apple's keychain doc). But will apple team like it ?
3-最后,如果你真的需要一个在重新安装app之后仍然存在的标识符(不经常发生),你可以使用Keychains(Apple的keychain doc)。但苹果团队会喜欢吗?
#3
1
UUID is just depreciated and so will be around for a while, Apple have not said much about this depreciation much yet, I would wait until they have more to say about this and maybe the will offer some alternative.
UUID只是贬值,因此将会出现一段时间,Apple还没有多说这种折旧,我会等到他们对此有更多的说法,也许会提供一些替代方案。
#4
1
Like this:
@interface UIDevice (UIDeviceAppIdentifier)
@property (readonly) NSString *deviceApplicationIdentifier;
@end
@implementation UIDevice (UIDeviceAppIdentifier)
- (NSString *) deviceApplicationIdentifier
{
static NSString *name = @"theDeviceApplicationIdentifier";
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *value = [defaults objectForKey: name];
if (!value)
{
value = (NSString *) CFUUIDCreateString (NULL, CFUUIDCreate(NULL));
[defaults setObject: value forKey: name];
[defaults synchronize];
}
return value;
}
@end
the iOS documentation more or less describes use of CFUUIDCreate() to create an identifier and suggests using UserDefaults to store it.
iOS文档或多或少地描述了使用CFUUIDCreate()来创建标识符并建议使用UserDefaults来存储它。
#5
0
The recommended way is by using UUID generation, and associate that with something that the user him/herself is willing to provide to the app.
推荐的方法是使用UUID生成,并将其与用户自己愿意为应用程序提供的内容相关联。
Then, store this data externally, where it could be retrieved again. There are probably other ways to do this easily, but this is the recommended way.
然后,将此数据存储在外部,以便再次检索。可能有其他方法可以轻松完成此操作,但这是推荐的方法。
#6
0
One solution would be to have the application issue a free in-app purchase.
一种解决方案是让应用程序发布免费的应用内购买。
This purchase would be:
此次购买将是:
-
Trackable, with a unique number (purchase) number which would be meaningful only to your app.
可追踪,具有唯一编号(购买)编号,仅对您的应用有意义。
-
Movable, if the person switches devices
如果人员切换设备,则可移动
-
Retrievable, if the app is deleted (or the phone is wiped and reloaded) - the In-App purchases can be restored.
可检索,如果应用程序被删除(或手机被擦除并重新加载) - 可以恢复应用程序内购买。
#7
0
Apple's documentation says:
Apple的文档说:
"Do not use the uniqueIdentifier property. To create a unique identifier specific to your app, you can call the CFUUIDCreate function to create a UUID, and write it to the defaults database using the NSUserDefaults class."
“不要使用uniqueIdentifier属性。要创建特定于应用程序的唯一标识符,可以调用CFUUIDCreate函数创建UUID,并使用NSUserDefaults类将其写入默认数据库。”
Here's a quick snippet:
这是一个快速片段:
CFUUIDRef udid = CFUUIDCreate(NULL);
NSString *udidString = (NSString *) CFUUIDCreateString(NULL, udid);