iOS UIDocumentBrowserViewController获取所选文件的URL路径

时间:2023-01-19 09:55:11

I am working on an iOS plugin for an unity project and for that i need to give user the possibility to browse the files on the device and pick a zip file.I need to pass the url path of the selected file or copy it to the local sandbox(if possible).For this i've used UIDocumentBrowserViewController where i've managed to make the interface for user to select the desired file.The problem is that i don't really get what's happening even though i've spent hours and hours on the Apple documentation.

我正在为一个统一项目的iOS插件工作,为此我需要让用户可以浏览设备上的文件并选择一个zip文件。我需要传递所选文件的url路径或将其复制到本地沙箱(如果可能的话)。为此我已经使用了UIDocumentBrowserViewController我已经设法为用户选择所需文件的界面。问题是即使我花了几个小时,我也没有真正得到正在发生的事情和Apple文档上的小时数。

Unless i install FileApp i can't see the Downloads folder in my app after using the search.If i install FileApp and build the app,i can check downloads directory.Shouldnt the new "Files" from ios 11 be able to show me the downloads folder without installing File App from AppStore?

除非我安装FileApp,否则在使用搜索后我无法在我的应用程序中看到Downloads文件夹。如果我安装FileApp并构建应用程序,我可以检查下载目录。来自ios 11的新“文件”能够显示给我在没有从AppStore安装File App的情况下下载文件夹?

I am a programmer with only 8 months experience in iOS so i'd appreciate any explanations that could make things clear for me.

我是一名只有8个月iOS经验的程序员,所以我很感激任何可以让我清楚的解释。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.


    retarziApple=[[NSArray alloc] initWithObjects:@"kUTTypePNG",@"kUTTypeJPEG",@"kUTTypePlainText",@"kUTTypeText",@"kUTTypeImage",nil];
    docBrowser=[[UIDocumentBrowserViewController alloc] initForOpeningFilesWithContentTypes:retarziApple];
    docBrowser.delegate=self;

    docBrowser.allowsDocumentCreation=NO;

    docBrowser.allowsPickingMultipleItems=NO;


    [self.window setRootViewController:docBrowser];


    return YES;
}

info plist:

<key>CFBundleDocumentTypes</key>
    <array>
        <dict>
            <key>CFBundleTypeIconFiles</key>
            <array/>
            <key>CFBundleTypeName</key>
            <string>Text</string>
            <key>LSHandlerRank</key>
            <string>Default</string>
            <key>LSItemContentTypes</key>
            <array>
                <string>public.plain-text</string>
                <string>public.png</string>
                <string>public.jpeg</string>
                <string>public.text</string>
                <string>public.image</string>
                <string>com.pkware.zip-archive</string>
            </array>
        </dict>
    </array>

1 个解决方案

#1


0  

  • If you want to pick a file and copy it to your app, you're looking for UIDocumentPickerViewController, not UIDocumentBrowserViewController
  • 如果你想选择一个文件并将其复制到你的应用程序,你正在寻找UIDocumentPickerViewController,而不是UIDocumentBrowserViewController

  • To see your files in the Files app, the files need to be in your Documents directory. Where are you copying it?
  • 要在“文件”应用程序中查看文件,文件需要位于“文档”目录中。你在哪里复制它?

#1


0  

  • If you want to pick a file and copy it to your app, you're looking for UIDocumentPickerViewController, not UIDocumentBrowserViewController
  • 如果你想选择一个文件并将其复制到你的应用程序,你正在寻找UIDocumentPickerViewController,而不是UIDocumentBrowserViewController

  • To see your files in the Files app, the files need to be in your Documents directory. Where are you copying it?
  • 要在“文件”应用程序中查看文件,文件需要位于“文档”目录中。你在哪里复制它?