使用Xamarin.iOS在iOS 8中访问临时目录

5

有人知道如何在Xamarin中获取iOS 8的tmp目录路径吗?


你能解释一下downvote吗?例如给出一个答案?是否有类似于var caches = Path.Combine (NSFileManager.DefaultManager.GetUrls(NSSearchPathDirectory.LibraryDirectory, NSSearchPathDomain.User) [0].Path, "Caches");这样的东西? - testing
2
不知道为什么会有人踩你的问题,我刚刚给你点了赞。;-) - asp_net
3个回答

7

只需尝试:

var documents = NSFileManager.DefaultManager
    .GetUrls(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomain.User)[0].Path;

var tmp = Path.Combine(documents, "../", "tmp");

谢谢。我会试一下。不过有一个问题:这个tmp目录是真正的目录还是Documents目录的子目录(可以通过iTunes文件共享提供给用户,并且会被备份)? - testing
有趣。他创建了这条路径 /Documents/../tmp/test.jpg。通过 ..,他成功进入正确的路径。 - testing
最近也在想那个奇怪的路径。有关详细概述,请参阅http://developer.xamarin.com/guides/ios/application_fundamentals/working_with_the_file_system/。 - asp_net

6
你可以直接使用。
var tmp = System.IO.Path.GetTempPath ();

这将返回您应用程序的临时目录。

1
//https://developer.xamarin.com/guides/ios/application_fundamentals/working_with_the_file_system
public string TempPath()
{           
    var documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
    var ret = Path.Combine(documents, "..", "tmp");
    return ret;
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接