首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何只得到一个NSUUID?

如何只得到一个NSUUID?
EN

Stack Overflow用户
提问于 2012-12-22 15:03:07
回答 3查看 4.4K关注 0票数 0

可能重复: iOS唯一用户标识符

对于我的申请,我需要电话uuid。我知道我可以用

代码语言:javascript
复制
NSUUID  *uuid = [NSUUID UUID];

但是每次我重新启动应用程序时,我都会收到不同的值。所以我不能像以前的uuid那样使用它(它总是一样的)。

我能做些什么来接收稳定和唯一的标识符?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-12-22 15:07:59

您正在考虑的是UDID (而不是UUID),它已被废弃,不再允许在App上使用。

下面是一种模拟它的技术:https://stackoverflow.com/a/8677177/832111

票数 2
EN

Stack Overflow用户

发布于 2012-12-22 15:07:33

UUID是128位值,UUID在空间和时间上都是唯一的,它结合了生成UUID的计算机的唯一值和表示自1582年10月15日00:00的100纳秒间隔的值。

所以每一秒你都会得到一个新的UUID。

您不能接收稳定和唯一的id,相反,您可以将接收到的id保存在密钥链或plist中并使用它。

票数 3
EN

Stack Overflow用户

发布于 2012-12-22 15:33:47

您可以使用OpenUDID库为每个设备生成唯一的UDID。它是可用的这里。从根本上说,它使用的是纸板。下面是一个例子

代码语言:javascript
复制
//First app, install->run->close->delete
UIPasteboard* board = [UIPasteboard pasteboardWithName:@"com.company.wtv" create:YES];
board.persistent=YES;// persistent to make what you write persist after your app closes, or gets deleted.
[board setValue:@"hello" forPasteboardType:@"com.company.wtv.sharedValue"];

//Second app, installed after first one is deleted and ran this one... While bundle identifier and bundle seed different (i tried it on adhoc, not really releasing the app, but i htink the same)
NSData* result=nil;
NSString*resultStr=nil;
result =[board valueForPasteboardType:@"com.company.wtv.sharedValue"];
resultStr=[[NSString alloc] initWithData:result encoding:NSUTF8StringEncoding];// I got resultStr containing hello
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14003865

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档