ios - dataWithContentsOfURL crash when running on iOS8 -
ios - dataWithContentsOfURL crash when running on iOS8 -
datawithcontentsofurl
crashes on ios8 when host not reachable , there net connection.
nsurl *url = [nsurl urlwithstring:myurl]; @try { info = [nsdata datawithcontentsofurl:url]; } @catch (nsexception *exception) { info = nil; } if(data!=nil){ [data writetofile:filepath atomically:yes]; }else{ info = [nsdata datawithcontentsoffile:filepath]; if (data==nil) { homecoming nil; } }
from documentation:
important: not utilize synchronous method request network-based urls. network-based urls, method can block current thread tens of seconds on slow network, resulting in poor user experience, , in ios, may cause app terminated.
if need know reason failure, utilize datawithcontentsofurl:options:error:
or
instead, non-file urls, consider using datataskwithurl:completionhandler:
method of nssession class.
ios iphone ios8
Comments
Post a Comment