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

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

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

android - How to create dynamically Fragment pager adapter -