需要加入SSKeyChain文件
传送门:SSKeyChain
//
// UniqueIDCreater.h
// Housemart
//
// Created by Haozhen Li on 13-9-26.
// Copyright (c) 2013年 refineit.com.cn. All rights reserved.
// #import <Foundation/Foundation.h>
#import "SSKeychain.h" @interface UniqueIDCreater : NSObject + (NSString *)uuid;
@end
//
// UniqueIDCreater.m
// Housemart
//
// Created by Haozhen Li on 13-9-26.
// Copyright (c) 2013年 refineit.com.cn. All rights reserved.
// #import "UniqueIDCreater.h" @implementation UniqueIDCreater #define kServiceKey @"com.housemart.housemart"
#define kAccountKey @"user" + (NSString *)uuid
{
NSString *_uuid = nil;
_uuid = [SSKeychain passwordForService:kServiceKey account:kAccountKey];
if (_uuid == nil) {
CFUUIDRef theUUID = CFUUIDCreate(NULL);
CFStringRef string = CFUUIDCreateString(NULL, theUUID);
CFRelease(theUUID); _uuid = [(NSString *)string autorelease];
[SSKeychain setPassword:_uuid forService:kServiceKey account:kAccountKey];
} // NSLog(@"[%@ %@] = %@", NSStringFromClass([self class]), NSStringFromSelector(_cmd), _uuid); return _uuid;
}
@end