【发布时间】:2017-02-07 15:35:42
【问题描述】:
我在 Xamarin 中编写了我的应用程序,首先针对 Android 进行了测试,然后针对 iOS 进行了测试。在 Android 上一切正常,而不是在 iOS 上。我的问题与PCLStorage有关,读取文件内容时失败,因为GetFileAsync结果是null,而不是CheckExistsAsync结果。
我的代码是:
public static async Task loadMyFile(Func<bool, Task> result) {
IFolder rootFolder = FileSystem.Current.LocalStorage;
await rootFolder.CheckExistsAsync("myfile.txt").ContinueWith(async (checkExistsTask) => {
if (checkExistsTask.Result == ExistenceCheckResult.FileExists) {
await rootFolder.GetFileAsync("myfile.txt").ContinueWith(async (getFileTask) => {
try
{
await getFileTask.Result.ReadAllTextAsync().ContinueWith(async (readTextTask) => {
try
{
if (!string.IsNullOrEmpty(readTextTask.Result))
{
doWork(readTextTask.Result);
await result(true);
return;
}
else
{
await result(false);
return;
}
}
catch (Exception e)
{
await result(false);
return;
}
});
}
catch (Exception e)
{
await result(false);
return;
}
});
} else {
await result(false);
return;
}
});
}
有什么想法吗? 谢谢。
【问题讨论】: