A convenient helper method for saving the UDID serial number of the target device (either iPhone, iPad or iPod) to User Preferences (via
NSUserDefaults).
/** Save the Device ID to User Preferences.
Please note that it does not save actual ID, but something similar.
@return
Returns true if the value has be written, false otherwise. Please note
that false value does not mean that there was an error.
*/
+ (BOOL)saveDeviceIdToUserPreferences {
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
if (!userDefaults) { return NO; }
NSString *deviceId = [userDefaults objectForKey:kUserPreferences_KeyForDeviceID];
if (!deviceId || [deviceId isEqualToString:@""]) {
[userDefaults setObject:[[NSUUID UUID] UUIDString] forKey:kUserPreferences_KeyForDeviceID];
return YES;
}
return NO;
}
Download the ready-for-use source file (.m) of Save iPhone, iPad, iPod UUID using NSUserDefaults
No comments:
Post a Comment