目标C,在iPad应用程序中保存文件

时间:2020-11-29 22:18:47

I am creating a sample application where it downloads 100 images from server and stores it in iPad.

我正在创建一个示例应用程序,它从服务器下载100个图像并将其存储在iPad中。

In XCode, I am using the NSURL to retrieve the image file and using NSData to save it into my local folder. I am able to save the images in my mac air desktop folder. But I want my application to be deployed in iPad. So here is my question:

在XCode中,我使用NSURL检索图像文件并使用NSData将其保存到我的本地文件夹中。我能够将图像保存在我的mac air桌面文件夹中。但我希望我的应用程序部署在iPad上。所以这是我的问题:

  • Where do I store the file in my iPad, so that my application can retrieve the images when needed?

    我在哪里将文件存储在iPad中,以便我的应用程序可以在需要时检索图像?

  • If possible can someone give me the code for saving the images in your iPad resource directory (or whatever directory needed). Just the code where you build the path will do good.

    如果可能,有人可以给我代码,用于将图像保存在iPad资源目录(或任何需要的目录)中。只需构建路径的代码就可以了。

I know this is kind of a basic question, since I am new to objective-C, I am kind of struggling with it.

我知道这是一个基本问题,因为我是客观C的新手,我有点挣扎。

2 个解决方案

#1


2  

Here is an example function how to retrieve the applications documents folder. In there you can create your own folder structure. This folder is also backed up by iTunes and will be preserved when doing application updates.

这是一个如何检索应用程序文档文件夹的示例函数。在那里,您可以创建自己的文件夹结构。此文件夹也由iTunes备份,并在进行应用程序更新时保留。

NSString* GetApplicationDocumentsDirectory() {
    static NSString* documentsDirectory = nil;
    if (documentsDirectory == nil) {
    documentsDirectory = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                               NSUserDomainMask,
                                                               YES)
                          objectAtIndex:0] retain];
    }
    return documentsDirectory;
}

#2


-1  

In my humble opinion, using a Core Data store would be the best approach for this.

在我看来,使用Core Data存储将是最好的方法。

#1


2  

Here is an example function how to retrieve the applications documents folder. In there you can create your own folder structure. This folder is also backed up by iTunes and will be preserved when doing application updates.

这是一个如何检索应用程序文档文件夹的示例函数。在那里,您可以创建自己的文件夹结构。此文件夹也由iTunes备份,并在进行应用程序更新时保留。

NSString* GetApplicationDocumentsDirectory() {
    static NSString* documentsDirectory = nil;
    if (documentsDirectory == nil) {
    documentsDirectory = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                               NSUserDomainMask,
                                                               YES)
                          objectAtIndex:0] retain];
    }
    return documentsDirectory;
}

#2


-1  

In my humble opinion, using a Core Data store would be the best approach for this.

在我看来,使用Core Data存储将是最好的方法。