【问题标题】:is it possible to browse files from my iphone application placed at any location in the device?是否可以从我放置在设备中任何位置的 iphone 应用程序中浏览文件?
【发布时间】:2013-11-21 04:27:49
【问题描述】:

我想在 iPhone 设备上浏览文本、pdf、图像等文件,就像在 android 中一样,我们可以在存储卡中浏览以上传或附加文件。但是对于 iPhone,我搜索了很多,但我没有找到任何解决方案。

【问题讨论】:

  • 这是用户级问题还是编程问题?这是越狱设备还是普通设备?
  • @rmaddy 这是编程级别的问题。我正在构建 iphone 应用程序。

标签: ios iphone nsfilemanager


【解决方案1】:

对于普通设备,答案是否定的。

iOS 中的每个应用程序都在其sandbox environment 上运行。您的应用无法看到放置在沙盒之外的任何数据。

出于安全原因,iOS 会在安装时将每个应用(包括其偏好设置和数据)置于沙盒中。沙盒是一组细粒度的控件,用于限制应用程序对文件、首选项、网络资源、硬件等的访问。作为沙盒过程的一部分,系统将每个应用程序安装在其自己的沙盒目录中,该目录充当应用程序及其数据的主目录。

对于越狱设备,它会破坏 snadbox 环境。因此,您可以访问设备中的任何文件。

【讨论】:

  • sry 我忘了提,这是编程级别的问题,但从你的回答看来,在那个级别上也是不可能的。但是有没有其他方法可以做到这一点..??提前谢谢。
【解决方案2】:
       Never do that becose  your app will be rejected,
       if you do like that and upload your app on App Store..... 
       Never use jailbreak in your app friend..  

【讨论】:

  • thanx ,我不知道。
【解决方案3】:

使用 UIImagePicker 选择图像

UIImagePickerController*    imagePicker = [[UIImagePickerController alloc] init];

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
{
    imagePicker.sourceType      =   UIImagePickerControllerSourceTypePhotoLibrary;
    imagePicker.mediaTypes      =   [UIImagePickerController availableMediaTypesForSourceType:imagePicker.sourceType];
    imagePicker.delegate        =   self;
    imagePicker.editing         =   YES;
    imagePicker.allowsEditing   =   YES;
    [self presentViewController:imagePicker animated:YES completion:nil];
}

要选择文件和 pdf,请使用 FileManager

NSFileManager *manager = [NSFileManager defaultManager];
NSArray *fileList = [manager directoryContentsAtPath:@"/MYFOLDER"];
NSArray *pdfList = [list filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF ENDSWITH '.pdf'"]];
NSLog(@"%@", pdfList);

【讨论】:

  • OP 要求一种在其应用程序的沙箱之外挑选文件的方法。自 iOS 2.0 起,directoryContentsAtPath 也已弃用:“返回给定目录中包含的目录和文件(包括符号链接)。(在 iOS 2.0 中已弃用。使用 contentsOfDirectoryAtPath:error: 代替。)”
  • @Shob-Zthanx 为您提供帮助,但我想创建界面,就像我们在 Windows 中浏览文件一样..
【解决方案4】:

是的,这是可能的,但它使用私有 API。如果您使用它并提交到应用商店,您的应用将被拒绝。 检查这个开源库FileSystem

【讨论】:

    猜你喜欢
    • 2010-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-19
    • 2021-06-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多