ios - NSData not returning bytes -


ok have password stored in keychain , attempting update password in keychain , on server. when user types in new password in uialertview password updated in keychain , on. problem having when cancel or try again value retrieve keychain retuned the string instead of in bytes.

i set new password in keychain using keychain wrapper

[keychainitem setobject:newpassword forkey:(__bridge id)(ksecvaluedata)]; 

the first time go through process works fine if attempt change again , go through process

-[__nscfstring bytes]: unrecognized selector sent instance  

it crashes in method when nsstring *keychainpassword = [[nsstring alloc] initwithdata:pass encoding:nsutf8stringencoding]; called. in nslog call retuning string of password , not bytes, reason why?

-(bool)checkifoldpasswordmatches { nslog(@"checkifpasswordmatches");   //gets password keychain nsdata *pass = [keychainitem objectforkey:(__bridge id)(ksecvaluedata)]; if (pass == nil || [pass length] == 0) {     [uialertview error:@"username , password not exist. must create login."]; }   //shows output of password should return bytes nslog(@"pass %@", pass); nsstring *keychainpassword = [[nsstring alloc] initwithdata:pass encoding:nsutf8stringencoding];  nslog(@"keychain %@", keychainpassword); if ([oldpassword isequaltostring:keychainpassword]) {     nslog(@"yes");     return yes; } else     nslog(@"no"); return no;  } 

ksecvaluedata specifies item data, not reference item (ksecvaluereference) or persistent reference (ksecvaluepersistentref). doesn't mean item value stored/returned nsdata instance.

the type of object put in type of object out, if put in nsstring nsstring.

you need change code either always use nsdata instance or always use nsstring, converting required.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -