iOS 生成 UUID(GUID)
2013-03-27 11:54
471 查看
iOS 生成 UUID(或者叫GUID)例子代码
NSString * gen_uuid()
{
CFUUIDRef uuid_ref = CFUUIDCreate(NULL);
CFStringRef uuid_string_ref= CFUUIDCreateString(NULL, uuid_ref);
CFRelease(uuid_ref);
NSString *uuid = [NSString stringWithString:(NSString*)uuid_string_ref];
CFRelease(uuid_string_ref);
return uuid;
}
在oc中,uuid的表示
1,用一个16个字节的数组表示
//guid
typedef struct {
#define KAUTH_GUID_SIZE 16/* 128-bit identifier */
unsignedchar g_guid[KAUTH_GUID_SIZE];
} guid_t;
//uuid
typedef
unsigned char
__darwin_uuid_t[16];//定义了一个元素类型为unsigned char,含有16个元素的数组类型__darwin_uuid_t,以后使用__darwin_uuid_t定义的类型都是一个含有16个字符的数组
typedef __darwin_uuid_t
uuid_t;
2,使用结构体表示
3,在iOS6.0之后,可以使用系统自带的NSUUID类
NSString * gen_uuid()
{
CFUUIDRef uuid_ref = CFUUIDCreate(NULL);
CFStringRef uuid_string_ref= CFUUIDCreateString(NULL, uuid_ref);
CFRelease(uuid_ref);
NSString *uuid = [NSString stringWithString:(NSString*)uuid_string_ref];
CFRelease(uuid_string_ref);
return uuid;
}
在oc中,uuid的表示
1,用一个16个字节的数组表示
//guid
typedef struct {
#define KAUTH_GUID_SIZE 16/* 128-bit identifier */
unsignedchar g_guid[KAUTH_GUID_SIZE];
} guid_t;
//uuid
typedef
unsigned char
__darwin_uuid_t[16];//定义了一个元素类型为unsigned char,含有16个元素的数组类型__darwin_uuid_t,以后使用__darwin_uuid_t定义的类型都是一个含有16个字符的数组
typedef __darwin_uuid_t
uuid_t;
2,使用结构体表示
typedef struct { UInt8 byte0; UInt8 byte1; UInt8 byte2; UInt8 byte3; UInt8 byte4; UInt8 byte5; UInt8 byte6; UInt8 byte7; UInt8 byte8; UInt8 byte9; UInt8 byte10; UInt8 byte11; UInt8 byte12; UInt8 byte13; UInt8 byte14; UInt8 byte15; } CFUUIDBytes;
3,在iOS6.0之后,可以使用系统自带的NSUUID类
相关文章推荐
- iOS 生成 UUID(GUID)
- 关于UUID和GUID,教你如何使用JDK自带的UUID生成主键。
- 跨平台生成GUID/UUID
- php中生成标准uuid(guid)的方法
- Java生成唯一GUID UUID
- GUID UUID 生成
- 怎样用java生成GUID与UUID
- 随机生成UUID(GUID)的方法
- 怎样用java生成GUID与UUID
- 备忘:生成GUID(UUID)
- 生成UUID、GUID
- iOS 中CFUUIDRef、 CFUUIDCreate 、CFUUIDCreateString 生成唯一字符串
- Javascript生成全局唯一标识符(GUID,UUID)的方法
- GUID(UUID)的生成
- IOS生成GUID
- 在Linux下生成GUID的程序,及编译错误 “uuid/uuid.h: No such file or directory” 的解决办法。
- php中生成标准uuid(guid)的方法
- php中生成标准uuid(guid)的方法
- ios生成guid代码
- CPP: 跨平台生成GUID/UUID