nsdocumentdirectory

Apps must follow the iOS Data Storage Guidelines or they will be rejected in app that contains .sqlite3

时光怂恿深爱的人放手 提交于 2019-11-28 02:19:18
问题 I created an ebook app and my app contains a lot of images and pdf files I was putting the downloaded images in /Library/Caches and putting the pdf files and .sqlite3 file in /Documents now my app is rejected and this is the reason 2.23 Apps must follow the iOS Data Storage Guidelines or they will be rejected Is this means that I have to move all what in /Documents to /Library/Caches? If I let the .sqlite3 file in /Documents, will the app reject again? Thanks in advance. 回答1: 2.23 means that

how to load image from local path ios swift (by path)

我怕爱的太早我们不能终老 提交于 2019-11-27 19:26:42
In my app I am storing an image in local storage and I am saving the path of that image in my database. How can I load the image from that path? Here is the code I am using in order to save the image: let myimage : UIImage = UIImage(data: data)! let fileManager = NSFileManager.defaultManager() let urls = fileManager.URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask) let documentDirectory = urls[0] as NSURL print(documentDirectory) let currentDate = NSDate() let dateFormatter = NSDateFormatter() dateFormatter.dateStyle = .NoStyle dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"

Read a .txt file inside documents directory

£可爱£侵袭症+ 提交于 2019-11-27 16:02:43
问题 How can I read a .txt file inside documents directory? Can you show me code? 回答1: NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"txtFile.txt"]; NSString *content = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:NULL]; 回答2: You can also use NSFileHandle for writing data in file and

App Updates, NSURL, and Documents Directory

安稳与你 提交于 2019-11-27 14:29:09
I have an app in the app store that uses Core Data to persist much of the data. The exception is storing images. I store images in subdirectories to the Documents directory and store an NSURL reference to that image in the appropriate object attribute in the core data store. We have noticed that, when an update makes it to the app store, those images are not found, and thus don't display, using the references stored with the previous version of the app. Now, I have a suspicion that the problem is that, since we are using development devices for testing, this issue propagates because the

Save file in document directory in swift 3?

醉酒当歌 提交于 2019-11-27 14:27:34
问题 I am saving files in a document directory in swift 3 with this code: fileManager = FileManager.default // let documentDirectory = fileManager?.urls(for: .documentDirectory, in: .userDomainMask).first as String var path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as String path = path + name let image = #imageLiteral(resourceName: "Notifications") let imageData = UIImageJPEGRepresentation(image, 0.5) let bool = fileManager?.createFile(atPath: path,

Delete specified file from document directory

◇◆丶佛笑我妖孽 提交于 2019-11-27 10:25:01
I want to delete an image from my app document directory. Code I have written to delete image is: -(void)removeImage:(NSString *)fileName { fileManager = [NSFileManager defaultManager]; paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); documentsPath = [paths objectAtIndex:0]; filePath = [documentsPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@", fileName]]; [fileManager removeItemAtPath:filePath error:NULL]; UIAlertView *removeSuccessFulAlert=[[UIAlertView alloc]initWithTitle:@"Congratulation:" message:@"Successfully removed" delegate

Document directory path change when rebuild application

独自空忆成欢 提交于 2019-11-27 06:03:23
问题 I download the video file from url and save it in document directory with this path: let destination: DownloadRequest.DownloadFileDestination = { _, _ in let pathComponent = "pack\(self.packID)-\(selectRow + 1).mp4" let directoryURL: URL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0] let folderPath: URL = directoryURL.appendingPathComponent("Downloads", isDirectory: true) let fileURL: URL = folderPath.appendingPathComponent(pathComponent) return (fileURL, [

Save Data to .plist File in Swift

走远了吗. 提交于 2019-11-26 22:14:31
I am trying to save data to a plist file in swift, but the data isn't showing up as it was saved when the plist is read. This is the code I was using. var documentsDirectory = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as NSString var path : NSString = documentsDirectory.stringByAppendingPathComponent("data.plist") var data : NSMutableDictionary = NSMutableDictionary(contentsOfFile: path) data.setObject(self.object, forKey: "key") data.writeToFile(path, atomically: true) Edit: I've heard that the best way to do this is write to the documents directory, so

how to load image from local path ios swift (by path)

泄露秘密 提交于 2019-11-26 19:52:46
问题 In my app I am storing an image in local storage and I am saving the path of that image in my database. How can I load the image from that path? Here is the code I am using in order to save the image: let myimage : UIImage = UIImage(data: data)! let fileManager = NSFileManager.defaultManager() let urls = fileManager.URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask) let documentDirectory = urls[0] as NSURL print(documentDirectory) let currentDate = NSDate() let dateFormatter =

Delete specified file from document directory

江枫思渺然 提交于 2019-11-26 17:56:26
问题 I want to delete an image from my app document directory. Code I have written to delete image is: -(void)removeImage:(NSString *)fileName { fileManager = [NSFileManager defaultManager]; paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); documentsPath = [paths objectAtIndex:0]; filePath = [documentsPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@", fileName]]; [fileManager removeItemAtPath:filePath error:NULL]; UIAlertView