0

Im currently developing and IOS application, For security purposes I would like to know how I can make the app send the device "UDID" to a server. So basically I need to know how to make the device "fetch" the udid and then take the udid and send it to a server as a "request".

If the UDID is "registered" in the MYSQL database, then the server will send back a confirmation.

Besides finding out how to get the udid, I may need additional help setting up the mysql database :$

Thanks!

4

2 回答 2

1

You can get the UUID of an iOS device using: CFUUIDRef udid = CFUUIDCreate(NULL); NSString *udidString = (NSString *) CFUUIDCreateString(NULL, udid);

(Apple dont like you to use the UDID).

As far as posting it to a server, I suggest using a JSON post method, and recording the success. A good JSON library is SBJson which can be found here. Youll need to create a HTTP post, get the response data, and use SBJson library to parse the response.

EDIT: OR instead of SBJson, as Carbonic acid kindly pointed out, you can use NSJSONSerialization. Also, as pointed out by Naz Mir, new UUID method used.

于 2013-09-05T17:31:07.597 回答
-1

Edit:

[[[UIDevice currentDevice] identifierForVendor] UUIDString] is not deprecated as I stated. Please go through the links below for information.

Getting UDID as stated above NSString *uuididentifier = [[[UIDevice currentDevice] identifierForVendor] UUIDString]; is deprecated and Apple no longer allows it. If your aim is to uniquely identify a device you can use SecureUDID or OpenUDID

I have used OpenUDID sometime back in one of our apps and using it is as simple as -

#import "OpenUDID.h"

[OpenUDID setOptOut:NO];
self.openUDID = [OpenUDID value];

Once you have the required value sending it to the server is trivial. You can use iOS networking library like AFNetworking to send and receive data. For example,

#import "AFHTTPRequestOperation.h"

NSURL *url = [NSURL URLWithString:@"Your sever URL"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
NSString *postString = [NSString stringWithFormat:@"&UDID=%@", self.
[request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPMethod:@"POST"];
AFHTTPRequestOperation *httpOperation = [[AFHTTPRequestOperation alloc] initWithRequest:request];

[httpOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *httpOperation, id responseObject) {

        //handle server response here
        NSLog(@"%@", [httpOperation responseString]); //this contains the servers response

}failure:^(AFHTTPRequestOperation *httpOperation, NSError *error) {          

        //handle server errors here
        NSLog(@"error: %@", [httpOperation error]);
}];
于 2013-09-05T18:20:50.110 回答