Create and save a unique identifier in MonoTouch

I am considering moving my application from standard iOS Objective-C to C # using MonoTouch.

In my Objective-C code, I generate a unique identifier and store it in NSUserDefaults to validate and verify subsequent logins. Here is the method I use for this:

- (NSString *) localUuid { NSString * ident = [[NSUserDefaults standardUserDefaults] objectForKey:UUID]; if(!ident){ CFUUIDRef uuidRef = CFUUIDCreate(NULL); CFStringRef uuidStringRef = CFUUIDCreateString(NULL, uuidRef); CFRelease(uuidRef); ident = [NSString stringWithString:(__bridge_transfer NSString *)uuidStringRef]; [[NSUserDefaults standardUserDefaults] setObject:ident forKey:UUID]; [[NSUserDefaults standardUserDefaults] synchronize]; } return ident; } 

I'm having trouble getting something similar to working with C # with MonoTouch.

I did not find the version of the CFUUID__ methods available in Mono.
Also, although there is an NSUserDefaults.StandardUserDefaults.SetValueForKey method, there is no simple GetValueForKey method.

Does anyone more experienced at Monotouch know a better way to do this?

+4
source share
1 answer

CFUUID not bound because it is easier to use the .NET CFUUID to achieve this. For instance.

 var uuid = Guid.NewGuid (); string s = uuid.ToString (); // if a string is preferred 

Also, although there is an NSUserDefaults.StandardUserDefaults.SetValueForKey method, there is no simple GetValueForKey method.

There are safe methods for doing the same, for example:

 NSUserDefaults settings = NSUserDefaults.StandardUserDefaults; settings.SetString (s, "key"); 
+10
source

All Articles