随即字符串的生成 & 利用udid 生成 唯一的字符串 appid

方法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;

}


你可能感兴趣的:(字符串)