iphone - Why can't I write Dictionary to plist? -
hey all,i got weird problem here
first create small project try write dictionary plist
declared textfield , button , code ibaction:
nsarray *localpathstemp = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *localdocpathtemp = [localpathstemp objectatindex:0]; nsstring *localfilepathtemp = [localdocpathtemp stringbyappendingpathcomponent:@"inputpassword.plist"]; nsmutabledictionary *localdictreadtemp = [[nsmutabledictionary alloc] initwithcontentsoffile:localfilepathtemp]; nsmutabledictionary *localserialnumber = [nsmutabledictionary dictionarywithobject:setsn.text forkey:@"input_serial_number"];
i try log write in
nslog(@"local dictionary : %@",[localdictreadtemp valueforkey:@"input_serial_number"]);//"input_serial_number=1" nslog(@"dictionary-localserialnumber %@",[localserialnumber valueforkey:@"input_serial_number"]);//1(i enter 1 @ textfield)
it's woks fine think
but move whole project
i got null
this code in original project(in alertview)
nsarray *localpathstemp = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *localdocpathtemp = [localpathstemp objectatindex:0]; nsstring *localfilepathtemp = [localdocpathtemp stringbyappendingpathcomponent:@"inputpassword.plist"]; nsmutabledictionary *localdictreadtemp = [[nsmutabledictionary alloc] initwithcontentsoffile:localfilepathtemp]; nsmutabledictionary *localserialnumber = [nsmutabledictionary dictionarywithobject:setlocalserialnumber.text forkey:@"input_serial_number"]; [localdictreadtemp addentriesfromdictionary:localserialnumber]; [localdictreadtemp writetofile:localfilepathtemp atomically:yes]; nslog(@"text in textfield:%@",setlocalserialnumber.text); nslog(@"local dictionary %@",localserialnumber);//"input_serial_number" = 1 nslog(@"dictionary-localdictreadtemp %@",[localdictreadtemp valueforkey:@"input_serial_number"]);//null
last result null
that's problem can't figure out,i got value @ sample ,but not work here .
why...did give wrong file path or ... ?
thanks replys
more information project
my application use control hardware device
if user first time use application
user have enter password , device serial number
device use bonjour search device
, default serial number/password url(this case in wifi)
ex.the url http://11.33.44.65/defaultsn_pwd.php
i plist file :
{ sn = 1; pwd = 777; }
this information user can't see it.
, application pop alertview 2 textfields
if text in textfield match sn/pwd form url
write in.
!!!if user in 3g environment , connect server control device
different wifi,because have give server device serial number
so
enter serial number(i need write in plist on iphone,but got null here)
take serial part of new url ex.
http://server/defaultsn_pwd.php
?sn=1
because can't write serial number in plist ,so can't right url
url http://server/defaultsn_pwd.php
?sn=null
crash program
this avery deadly issues ,please me figure problem out....
i trapped in problem long...
nsmutabledictionary *localdictreadtemp = [[nsmutabledictionary alloc] initwithcontentsoffile:localfilepathtemp];
i betcha problem line. unless writing file location elsewhere in code, there no file @ localfilepathtemp
. since file empty, initwithcontentsoffile
returns nil
dictionary, , rest chain reaction of nil objects.
try this:
if ([[nsfilemanager defaultmanager] fileexistsatpath:localfilepathtemp]) { nslog(@"file exists @ %@",localfilepathtemp); } else nslog(@"some dude internet solved problem, should go choose answer");
Comments
Post a Comment