iOS using Keychain specific methods

Source: Internet
Author: User

Dictionary write:

if ([self.currentuseraccount length] > 0) {

Keychainitemwrapper *keychainitem = [[Keychainitemwrapper alloc]initwithidentifier:@ "UserAccount" accessGroup:nil];
if (Keychainitem) {

if ([[Keychainitem objectforkey:ksecattraccount] length] > 0) {

already has data

Nsmutablearray *accountarray = [[Keychainitem objectforkey:ksecattraccount] propertylist];
if (Accountarray && [Accountarray Iskindofclass:[nsmutablearray class]] && [accountarray count] > 0)
{
Just store the different user account
Nsuinteger indexoftheobject = [Accountarray indexOfObject:self.currentUserAccount];
if (Indexoftheobject > [Accountarray count]) {

[Accountarray AddObject:self.currentUserAccount];
[Keychainitem setobject:[accountarray description] Forkey: (ID) ksecattraccount];

//}
for (int index = 0; index < [Accountarray count]; index + +) {

NSLog (@ "The value is%@", [Accountarray Objectatindex:index]);
}
}

}else{

Has no data
Nsmutablearray *accountarray = [Nsmutablearray arrayWithObject:self.currentUserAccount];
[Keychainitem setobject:[accountarray description] Forkey: (ID) ksecattraccount];

}
}
}

Dictionary read:

Keychainitemwrapper *tokenkeychainitem = [[[Keychainitemwrapper alloc]initwithidentifier:@ ' UserAuthToken ' Accessgroup:nil]autorelease];
if (Tokenkeychainitem && [[Tokenkeychainitem objectforkey:ksecvaluedata] length] > 0) {

[Tokenkeychainitem Resetkeychainitem];

Nsmutabledictionary *dictionary = [[Tokenkeychainitem objectforkey:ksecvaluedata] propertylist];

if (dictionary && [dictionary iskindofclass:[nsmutabledictionary class]] && [dictionary count] > 0) {

Self.tokenvalue = [Dictionary valueforkey:@ "token"];
Push the View
selectchildviewcontroller* Pushview = [[Selectchildviewcontroller alloc]init];
[Pushview SetTokenValue:self.tokenValue];
[Self.navigationcontroller Pushviewcontroller:pushview Animated:yes];
[Pushview release];
}
((kidsappdelegate*) [[[UIApplication Sharedapplication]delegate]]. Logintoken = Self.tokenvalue;


[Tokenkeychainitem Resetkeychainitem];
Has token
/*loginmanager *tmp = [[Loginmanager alloc]initwithusername:@ "" withpassword:@ "" withToken:self.tokenValue];
Self.login = tmp;
[TMP release];
[Self.login dologin];*/


}

Array write:

if ([self.currentuseraccount length] > 0) {

Keychainitemwrapper *keychainitem = [[Keychainitemwrapper alloc]initwithidentifier:@ "UserAccount" accessGroup:nil];
if (Keychainitem) {

if ([[Keychainitem objectforkey:ksecattraccount] length] > 0) {

already has data

Nsmutablearray *accountarray = [[Keychainitem objectforkey:ksecattraccount] propertylist];
if (Accountarray && [Accountarray Iskindofclass:[nsmutablearray class]] && [accountarray count] > 0)
{
Just store the different user account
Nsuinteger indexoftheobject = [Accountarray indexOfObject:self.currentUserAccount];
if (Indexoftheobject > [Accountarray count]) {

[Accountarray AddObject:self.currentUserAccount];
[Keychainitem setobject:[accountarray description] Forkey: (ID) ksecattraccount];

//}
for (int index = 0; index < [Accountarray count]; index + +) {

NSLog (@ "The value is%@", [Accountarray Objectatindex:index]);
}
}

}else{

Has no data
Nsmutablearray *accountarray = [Nsmutablearray arrayWithObject:self.currentUserAccount];
[Keychainitem setobject:[accountarray description] Forkey: (ID) ksecattraccount];

}
}
}

Array reads:

Keychainitemwrapper *keychainitem = [[Keychainitemwrapper alloc]initwithidentifier:@ "UserAccount" accessGroup:nil];
Self.accountarray = [Nsmutablearray array];
Self.lasttimeaccount = @ "";

if (Keychainitem) {

[Keychainitem Resetkeychainitem];
First get the old token if found delete//ksecvaluedata
if ([[Keychainitem objectforkey:ksecattraccount] length] > 0) {

Nsmutablearray *orignalarray = [[Keychainitem objectforkey:ksecattraccount] propertylist];

if (Orignalarray && [Orignalarray Iskindofclass:[nsmutablearray class]] && [orignalarray count] > 0)
{
Move the repeated item
Nsinteger index = [Orignalarray count]-1;
For (ID object in [orignalarray Reverseobjectenumerator]) {
if ([Orignalarray indexofobject:object inrange:nsmakerange (0, index)]! = Nsnotfound) {
[Orignalarray Removeobjectatindex:index];
}
index--;
}
}
Self.accountarray = Orignalarray;
if ([Self.accountarray count] > 0) {

Self.lasttimeaccount = [Self.accountarray objectatindex:[self.accountarray count]-1];
Self.switchBtn.hidden = NO;

}

}
[Keychainitem release];
}

iOS using Keychain specific methods

Related Article

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.