ios - Can't read data that was written with writeToFile:atomically -


i have these 2 lines of code:

[[nsdata datawithcontentsofurl:[nsurl urlwithstring:@"http://somepath.com/first.plist"]] writetofile:@"first.plist" atomically:yes]; nsdictionary *dtmp=[[nsdictionary alloc] initwithcontentsoffile:[[nsbundle mainbundle] pathforresource:@"first" oftype:@"plist"]]; 

but dtmp null. i'm not specifying path, it's supposed stored in root directory, right? mistake?

there couple of problems code.

you should not use synchronous networking calls datawithcontentsofurl. willl block ui. @ nsurlsession instead.

you can't write file in root directory. ios apps limited few sandbox directories apps' documents , caches directories.

you should write code writes , reads 1 of allowed sandbox directories.

also, don't write compound statements. makes hard read , debug. 1 thing on each line.

check return value @ each step see what's going wrong.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -