【问题标题】:What is the correct way to get the iOS Library folder using Xamarin.iOS?使用 Xamarin.iOS 获取 iOS 库文件夹的正确方法是什么?
【发布时间】:2013-12-11 11:54:05
【问题描述】:

这将获得我的 iOS 应用的文档根目录:

Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)

有没有类似的东西可以进入 Library 文件夹?

【问题讨论】:

    标签: c# ios xamarin.ios xamarin


    【解决方案1】:
    var docsPath = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments);
    var libPath = Path.Combine (docsPath, "..", "Library");
    

    【讨论】:

    • 如果 Apple 明天更改 Library 文件夹的位置,那么...?
    • 那么每个应用程序都会被破坏,因为 Apple 记录了这一点并且不提供 API 来检索目录。 developer.apple.com/library/ios/documentation/FileManagement/…
    • 我认为 iOS 8 改变了这一点。有人有这方面的更新吗?
    • @Lereveme Xamarin API 会自动检查操作系统版本。上面的代码适用于所有版本的 iOS。
    • 嗨@Krumelur - 请参阅我提交的答案。它来自 Xamarin 的 iOS 文件系统帮助文档。
    【解决方案2】:

    目前(iOS 12)您可以通过以下方式检索 Library 路径:

    var libraryPath = Environment.GetFolderPath(Environment.SpecialFolder.Resources);
    
    ".../APP-UUID/Library"
    

    对于嵌套在 Library 文件夹中的目录,例如本地应用缓存,您可以这样做:

    var pathToCache = Path.Combine(libraryPath, "Caches"); 
    
    ".../APP-UUID/Library/Caches"
    

    Xamarin IOS 上可能感兴趣的其他目录:

    SpecialFolder.Favorites =   ".../APP-UUID/Library/Favorites"
    SpecialFolder.MyDocuments = ".../APP-UUID/Documents"
    SpecialFolder.MyMusic =     ".../APP-UUID/Documents/Music"
    SpecialFolder.MyPictures =  ".../APP-UUID/Documents/Pictures"
    SpecialFolder.MyVideos =    ".../APP-UUID/Documents/Videos"
    SpecialFolder.Desktop =     ".../APP-UUID/Documents/Desktop"
    

    更多选项可以在Xamarin Docs for File System上探索

    【讨论】:

    • 当前的答案已经有几年的历史了,虽然它们很有帮助,但我想我会与大家分享我的最新发现。
    【解决方案3】:

    在 iOS8 中,我使用了这个并且它有效:

    NSFileManager.DefaultManager.GetUrls (NSSearchPathDirectory.LibraryDirectory, NSSearchPathDomain.User) [0].Path
    

    我从 Xamarin 的 page about the iOS file system 得到这个。它说“iOS 8 注意:本文档的部分内容受 iOS 8 更改的影响。如果您的应用程序使用 Environment.SpecialFolder 或计算诸如“../Documents”之类的相对路径,您应该阅读 Apple 的此技术说明。更新信息也是可在 iOS 文件系统基础中获得。”

    【讨论】:

    • 我在您分享的链接上找不到此代码。你的解释也很模糊。我无法理解。
    猜你喜欢
    • 2021-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    • 1970-01-01
    • 2019-04-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多