方法1
//利用udid 生成 唯一的字符串 appid
-(NSString*) stringWithUUID
{
CFUUIDRef uuidObj = CFUUIDCreate(kCFAllocatorDefault);
CFStringRef strRef = CFUUIDCreateString(kCFAllocatorDefault, uuidObj);
NSString* appid = [NSStringstringWithString:(NSString*)strRef];
CFRelease(strRef);
CFRelease(uuidObj);
uuidString = [uuidString stringByReplacingOccurrencesOfString:@"-" withString:@""];
return appid;
}
方法2
-(NSString*) stringWithUUID:(int)len
{
NSString *appid = @"abcdefghigklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
NSMutableString *randomString = [NSMutableString stringWithCapacity: len];
for (int i=0; i<len; i++) {
[randomString appendFormat: @"%C", [appid characterAtIndex: arc4random() % [appid length]]];
}
return appid;
}
本文介绍了两种在iOS应用中生成唯一标识符UUID的方法。方法一使用CFUUIDRef创建UUID,并将其转换为字符串形式。方法二则通过随机选择字符集中的字符来生成指定长度的UUID。
543

被折叠的 条评论
为什么被折叠?



