如何获取iPhone中保存的所有文档?
How to get all documents saved in iPhone?
我使用了下面的代码来获取文件
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
if([paths count] > 0)
{
NSString *documentsDirectory = [paths objectAtIndex:0];
NSLog(@"%@",documentsDirectory);
NSError *error = nil;
NSArray *documentArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsDirectory error:&error];
if(error)
{
NSLog(@"Could not get list of documents in directory, error = %@",error);
}
else
{
NSLog(@"Hello %@",documentArray);
arrdocument = documentArray;
}
}
但它只显示我的应用程序中的文档,而不是应用程序外部的文档。
您无法访问其他应用程序中的文件:每个应用程序都是沙盒化的。
我建议您阅读 Apple 的 File System Basics:
Every App Is an Island
An iOS app’s interactions with the file system are limited mostly to the directories inside the app’s sandbox. During installation of a new app, the installer creates a number of containers for the app. Each container has a specific role. The bundle container holds the app’s bundle, whereas the data container holds data for both the application and the user. The data container is further divided into a number of directories that the app can use to sort and organize its data. The app may also request access to additional containers—for example, the iCloud container—at runtime.
These containers constitute the app’s primary view of the file system.
Because it is in a sandbox, an app is generally prohibited from accessing or creating files outside its containers. One exception to this rule occurs when an app uses public system interfaces to access things such as the user’s contacts or music. In those cases, the system frameworks handle any file-related operations needed to read from or modify the appropriate data stores.
Every App Is an Island
An iOS app’s interactions with the file system
are limited mostly to the directories inside the app’s sandbox. During
installation of a new app, the installer creates a number of
containers for the app. Each container has a specific role. The bundle
container holds the app’s bundle, whereas the data container holds
data for both the application and the user. The data container is
further divided into a number of directories that the app can use to
sort and organize its data. The app may also request access to
additional containers—for example, the iCloud container—at runtime.
您不能访问其他应用程序中的文件:是的。
但 Apple 提供了设计基于 NSDocument 的应用程序以在沙箱外共享文件的方法,沙箱是所有具有根公共包标识符的应用程序的公共共享文件夹。
除此之外,您还可以使用 iCloud public 存储在其他应用程序(如 Flicker、Dropbox)之间共享数据。下面是一些教程链接:
https://www.raywenderlich.com/12779/icloud-and-uidocument-beyond-the-basics-part-1
我使用了下面的代码来获取文件
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
if([paths count] > 0)
{
NSString *documentsDirectory = [paths objectAtIndex:0];
NSLog(@"%@",documentsDirectory);
NSError *error = nil;
NSArray *documentArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsDirectory error:&error];
if(error)
{
NSLog(@"Could not get list of documents in directory, error = %@",error);
}
else
{
NSLog(@"Hello %@",documentArray);
arrdocument = documentArray;
}
}
但它只显示我的应用程序中的文档,而不是应用程序外部的文档。
您无法访问其他应用程序中的文件:每个应用程序都是沙盒化的。
我建议您阅读 Apple 的 File System Basics:
Every App Is an Island
An iOS app’s interactions with the file system are limited mostly to the directories inside the app’s sandbox. During installation of a new app, the installer creates a number of containers for the app. Each container has a specific role. The bundle container holds the app’s bundle, whereas the data container holds data for both the application and the user. The data container is further divided into a number of directories that the app can use to sort and organize its data. The app may also request access to additional containers—for example, the iCloud container—at runtime.
These containers constitute the app’s primary view of the file system.
Because it is in a sandbox, an app is generally prohibited from accessing or creating files outside its containers. One exception to this rule occurs when an app uses public system interfaces to access things such as the user’s contacts or music. In those cases, the system frameworks handle any file-related operations needed to read from or modify the appropriate data stores.
Every App Is an Island
An iOS app’s interactions with the file system are limited mostly to the directories inside the app’s sandbox. During installation of a new app, the installer creates a number of containers for the app. Each container has a specific role. The bundle container holds the app’s bundle, whereas the data container holds data for both the application and the user. The data container is further divided into a number of directories that the app can use to sort and organize its data. The app may also request access to additional containers—for example, the iCloud container—at runtime.
您不能访问其他应用程序中的文件:是的。
但 Apple 提供了设计基于 NSDocument 的应用程序以在沙箱外共享文件的方法,沙箱是所有具有根公共包标识符的应用程序的公共共享文件夹。
除此之外,您还可以使用 iCloud public 存储在其他应用程序(如 Flicker、Dropbox)之间共享数据。下面是一些教程链接:
https://www.raywenderlich.com/12779/icloud-and-uidocument-beyond-the-basics-part-1