A UUID created by CFUUIDCreate
is unique if a user uninstalls and re-installs the app: you will get a new one each time.
But you might want it to be not unique, i. e. it should stay the same when the user uninstalls and re-installs the app. This requires a bit of effort, since the most reliable per-device-identifier seems to be the MAC address. You could query the MAC and use that as UUID.
Edit: One needs to always query the MAC of the same interface, of course. I guess the best bet is with en0
. The MAC is always present, even if the interface has no IP/is down.
Edit 2: As was pointed out by others, the preferred solution since iOS 6 is -[UIDevice identifierForVendor]. In most cases, you should be able use it as a drop-in replacement to the old -[UIDevice uniqueIdentifier]
(but a UUID that is created when the app starts for the first time is what Apple seems to want you to use).
Edit 3: So this major point doesn't get lost in the comment noise: do not use the MAC as UUID, create a hash using the MAC. That hash will always create the same result every time, even across reinstalls and apps (if the hashing is done in the same way). Anyways, nowadays (2013) this isn't necessary any more except if you need a "stable" device identifier on iOS < 6.0.
Edit 4: In iOS 7, Apple now always returns a fixed value when querying the MAC to specifically thwart the MAC as base for an ID scheme. So you now really should use -[UIDevice identifierForVendor] or create a per-install UUID.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…