Generate unique characters in ios
How would I create a unique set of characters from a given string? For example I want to give a user a unique say 7 characters as a unique username (other than an email). This could be but doesnt 开发者_开发技巧have to be based on their email.
For a simple unique string that is not based on anything in particular but is guaranteed to be unique across all devices for all time, you could use a CFUUID. Something like:
CFUUIDRef identifier = CFUUIDCreate(NULL);
NSString* identifierString = (NSString*)CFUUIDCreateString(NULL, identifier);
CFRelease(identifier);
Now I'm making my comment into an answer. :)
I would suggest you set up a server on the cloud side. Then your server could decide the unique name for each user / device.
It may double your workload, since now you need to take care of the server as well. But it's totally worth it. With a server and this server-client model you will have all the flexibility of managing your user sign-in / sign-up issues without modifying much code in your client (the app).
精彩评论