ios5 - Copy data file from Xcode to iPad sandbox -
i created app in xcode , added text file app open , display.
how can text file ipad sandbox documents directory testing?
there few things need do:
- create path documents directory
- make sure text file in app bundle (drag/drop xcode should fine)
- copy text file name app bundle documents directory
try this:
// documents path nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *documentspath = [paths objectatindex:0]; // destination path nsstring *fileindocumentspath = [documentspath stringbyappendingpathcomponent:@"name-of-your-file.txt"]; // origin path nsstring *fileinbundlepath = [[nsbundle mainbundle] pathforresource:@"name-of-your-file" oftype:@"txt"]; // file manager copying nserror *error = nil; nsfilemanager *filemanager = [nsfilemanager defaultmanager]; [filemanager copyitematpath:fileinbundlepath topath:fileindocumentspath error:&error];
Comments
Post a Comment