gpt4 book ai didi

iphone - 非 iCloud 使用 UIDocument

转载 作者:可可西里 更新时间:2023-11-01 05:04:50 25 4
gpt4 key购买 nike

当用户禁用 iCloud 时,我尝试在没有 iCloud 的情况下使用 UIDocument。我有以下代码:

NSURL *url;
if (_isiCloudEnabled) {
NSURL *ubiq = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];
url = [ubiq URLByAppendingPathComponent:[NSString stringWithFormat:@"%f.adoc",[[NSDate date] timeIntervalSince1970]]];
} else {
NSString *homeDirectoryPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *newFilePath = [homeDirectoryPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%f.adoc", [[NSDate date] timeIntervalSince1970]]];
url = [NSURL URLWithString:newFilePath];
}

ASListyDocument *d = [[ASListyDocument alloc] initWithFileURL:url];

这段代码给我错误:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'must pass a valid file URL to -[UIDocument initWithFileURL:]'

有什么想法吗?我查看了调试器中的 URL - 它似乎有效。我尝试在模拟器和手机上运行它 - 同样的问题!

顺便说一下,我在运行 iOS 5.0 的设备上运行,以防万一。

最佳答案

这可能是您正在构建的 URL

NSString *homeDirectoryPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *newFilePath = [homeDirectoryPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%f.adoc", [[NSDate date] timeIntervalSince1970]]];
url = [NSURL URLWithString:newFilePath];

实际上不是 URL,而是路径。不要忘记有效的 URL 需要一个方案;对于文件,这是“file://”。尝试使用 [NSURL fileURLWithPath:]

构建文件 URL
url = [NSURL fileURLWithPath:newFilePath];

关于iphone - 非 iCloud 使用 UIDocument,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10227750/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com