IOS get phone Unique ID-b

Source: Internet
Author: User

Storage in Keychainquery can count user usage

-(void) gathermessage{

Capture User Device information

Nsuserdefaults *userdefaults=[nsuserdefaults Standarduserdefaults];

NSDate *loaddate=[nsdate Date];

NSDate *lastdata=[userdefaults valueforkey:@ "Loadforday"];

NSDateFormatter *dateformatter=[[nsdateformatter Alloc]init];

[Dateformatter setdateformat:@ "Yyyy/mm/dd"];

NSString *lastd=[dateformatter Stringfromdate:lastdata];

NSString *nowd=[dateformatter Stringfromdate:loaddate];

if (![ LASTD Isequaltostring:nowd]) {

[Userdefaults setobject:loaddate forkey:@ "Loadforday"];

Get device model

NSString *devicemodel=[commendata Getcurrentdevicemodel];

Identifierforvendor as a unique identifier

NSString *IDENTIFIERSTR = [[[Uidevice Currentdevice] Identifierforvendor] uuidstring];

NSString * Const Key_username_password = @ "Com.int-yt.kyks.usernamepassword";

NSString * Const Key_password = @ "Com.int-yt.kyks.password";

Nsmutabledictionary *usernamepasswordkvpairs = [Nsmutabledictionary dictionary];

[Usernamepasswordkvpairs setobject:identifierstr Forkey:key_password];

Nsmutabledictionary *readuserpwd = (nsmutabledictionary *) [Commendata Load:key_username_password];

if (Readuserpwd==nil) {

Save

[Commendata Save:key_username_password Data:usernamepasswordkvpairs];

Readuserpwd = (nsmutabledictionary *) [Commendata Load:key_username_password];

}

Call Interface Record login information

NSString *string= [nsstring stringwithformat:@]% @cdpt/api/uselog?access_token=123&imeiid=%@&mtype=%@& Device_platform=2 ", baseurlstring, [Readuserpwd Objectforkey:key_password],devicemodel];

Nsurl *url = [Nsurl urlwithstring:string];

Nsurlrequest *request = [Nsurlrequest Requestwithurl:url];

NSLog (@ "%@", string);

Afhttprequestoperation *operation = [[Afhttprequestoperation alloc] initwithrequest:request];

Operation.responseserializer = [Afjsonresponseserializer serializer];

[Operation setcompletionblockwithsuccess:^ (afhttprequestoperation *operation, id responseobject) {

} failure:^ (Afhttprequestoperation *operation, Nserror *error) {

}];

[Operation start];

}

}

Save

+ (void) Save: (NSString *) service data: (ID) Data {

Get Search Dictionary

Nsmutabledictionary *keychainquery = [self getkeychainquery:service];

Delete old item before add New item

Secitemdelete ((__bridge cfdictionaryref) keychainquery);

Add new object to search dictionary (attention:the data format)

[Keychainquery setobject:[nskeyedarchiver Archiveddatawithrootobject:data] Forkey: (__bridge ID) kSecValueData];

ADD item to keychain with the search dictionary

Secitemadd ((__bridge cfdictionaryref) keychainquery, NULL);

}

+ (Nsmutabledictionary *) Getkeychainquery: (NSString *) Service {

return [nsmutabledictionary Dictionarywithobjectsandkeys:

(__bridge ID) Ksecclassgenericpassword, (__bridge ID) ksecclass,

Service, (__bridge ID) ksecattrservice,

Service, (__bridge ID) ksecattraccount,

(__bridge ID) ksecattraccessibleafterfirstunlock, (__bridge ID) ksecattraccessible,

NIL];

}

Take

+ (ID) Load: (NSString *) Service {

ID ret = NIL;

Nsmutabledictionary *keychainquery = [self getkeychainquery:service];

Configure the search setting

Since in our simple case we is expecting only a single attribute to be returned (the password) we can set the attribute Ksecreturndata to Kcfbooleantrue

[Keychainquery setobject: (__bridge ID) kcfbooleantrue forkey: (__bridge ID) ksecreturndata];

[Keychainquery setobject: (__bridge ID) ksecmatchlimitone forkey: (__bridge ID) ksecmatchlimit];

Cfdataref keyData = NULL;

if (secitemcopymatching (__bridge cfdictionaryref) keychainquery, (Cftyperef *) &keydata) = = NOERR) {

@try {

ret = [Nskeyedunarchiver unarchiveobjectwithdata: (__bridge NSData *) KeyData];

} @catch (NSException *e) {

NSLog (@ "Unarchive of%@ failed:%@", service, E);

} @finally {

}

}

if (KeyData)

Cfrelease (KeyData);

return ret;

}

+ (void) Delete: (NSString *) Service {

Nsmutabledictionary *keychainquery = [self getkeychainquery:service];

Secitemdelete ((__bridge cfdictionaryref) keychainquery);

}

Get the device model

+ (NSString *) Getcurrentdevicemodel

{

int mib[2];

size_t Len;

Char *machine;

Mib[0] = CTL_HW;

MIB[1] = Hw_machine;

Sysctl (MIB, 2, NULL, &len, NULL, 0);

Machine = malloc (len);

Sysctl (MIB, 2, machine, &len, NULL, 0);

NSString *platform = [NSString stringwithcstring:machine encoding:nsutf8stringencoding];

Free (machine);

return platform;

}

IOS get phone Unique ID-b

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.