objective c - iOS 9 Error write .plist -


my app errors after update ios 9. can't write .plist file in project.

-(bool)writedictionarytoplist:(nsdictionary*)plistdict {     nsstring *path = [[nsbundle mainbundle] pathforresource:@"history" oftype:@"plist"];      nsmutabledictionary *dict = [[nsmutabledictionary alloc] init];     [dict setvaluesforkeyswithdictionary:plistdict];      nsdictionary *savedict = [nsdictionary dictionarywithdictionary:dict];     bool result = [savedict writetofile:path atomically:yes];      return result; } 

result no.

but ios 7 , ios 8 works fine.

how can fix ?

use dictionarywithcontentsoffile: write dictionary plist

nsstring *path = [[nsbundle mainbundle] pathforresource:@"history" oftype:@"plist"]; nsmutabledictionary *dict = [nsmutabledictionary dictionarywithcontentsoffile:path]; bool result = [dict writetofile:path atomically:yes]; 

note since plist app resource cant write file, hence create plist file in documents directory , write file.

nsstring *path = [nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes) objectatindex:0]; path = [path stringbyappendingstring:@"/history.plist"]; bool result = [dict writetofile:path atomically:yes]; 

retrieve data plist

nsmutabledictionary *dict = [nsmutabledictionary dictionarywithcontentsoffile:path]; 

update add nsapptransportsecurity dictionary , first child should bool named nsallowsarbitraryloads set yes.

<key>nsapptransportsecurity</key>     <dict>         <key>nsallowsarbitraryloads</key>         <true/>     </dict> 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -