隨即字串的生成 & 利用udid 生成 唯一的字串 appid
阿新 • • 發佈:2019-01-27
方法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:@"-"
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;
}