I need to get deviceUUID from a phone in a NSString format. Now I have this:
NSString *deviceId = [UIDevice currentDevice].identifierForVendor;
Because what I had before, which was:
NSString *deviceId = [UIDevice currentDevice].uniqueIdentifier;
Gives me an error now.
But with the first sentence, I got an alert:
Incompatible pointer types initializing 'NSString *' with an expression of type 'NSUUID *'
As the error tells you, identifierForVendor
returns an object of class NSUUID
, not a NSString.
If you need a NSString use this:
NSUUID *identifierForVendor = [[UIDevice currentDevice] identifierForVendor];
NSString *deviceId = [identifierForVendor UUIDString];
For anyone looking for how to convert NSUUID to NSString
ObjC
NSString *uuid = [[NSUUID UUID] UUIDString];
Swift
NSUUID().UUIDString
Swift 3
UUID().uuidString
EDITE : As OP's requirement I reopen my deleted answer and I mention here @Matthias's answer is correct and by using following code you get new device_id each time whenever run this code.
Use following code:
CFUUIDRef uuidRef = CFUUIDCreate(kCFAllocatorDefault);
NSString *uuidString = (NSString *)CFBridgingRelease(CFUUIDCreateString(NULL,uuidRef));
CFRelease(uuidRef);
NSLog(@"%@", uuidString);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With