ios8 - Writing/reading to paths with interleaved double dots fails on iOS 8 -
this code fails on ios 8, although work on ios 7
uiimage *imagetest = ... nsstring *file = @"../documents/test.png"; nsstring *fullpath = [[[nsbundle mainbundle] bundlepath] stringbyappendingpathcomponent: file]; [uiimagepngrepresentation(imagetest) writetofile: fullpath atomically: yes]; uiimage *image = [uiimage imagenamed: file];
on ios 8 need use instead
nsstring *file = [[nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes) objectatindex:0] stringbyappendingpathcomponent:@"test.png"]; [uiimagepngrepresentation(imagetest) writetofile:file atomically:yes]; uiimage *image = [[uiimage alloc] initwithcontentsoffile: file];
...but have refactor project , third party library works paths relative main bundle.
it seems me paths "/pathtomainbundle/myapp.app/../documents/something"
either not resolved, or not allowed @ ios 8
that path should same "/pathtomainbundle/documents/something"
in ios8, resource directory(app.app), data directory(nscachesdirectory, nstemporarydirectory,..) managed separately below.
- ios7 directory hierarchy
- app uuid
- documents
- library
- caches
- preferences
- tmp
- app.app
- app uuid
- ios8 directory hierarchy
- resource directory uuid
- app.app
- data directory uuid
- documents
- library
- caches
- preferences
- tmp
- resource directory uuid
so, should fix code based on absolute path in ios8.
uiimage *imagetest = ... nsstring *fullpath = [[nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes) firstobject] stringbyappendingpathcomponent:@"test.png"]; [uiimagepngrepresentation(imagetest) writetofile: fullpath atomically: yes]; uiimage *image = [uiimage imagenamed: fullpath];
Comments
Post a Comment