Xcode:CloudKit中的CKAsset

时间:2016-01-10 03:56:57

标签: cloudkit ckasset

在我的代码中,

-1

错误将出现在“NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *localPath = [[paths objectAtIndex: 0] stringByAppendingPathComponent: @"temporary.png"]; NSLog(@"local path=%@", localPath); [UIImagePNGRepresentation(self.scriptPicture.image) writeToFile:localPath atomically:YES]; //[opData.scripts writeToFile:localPath atomically:YES]; if ([[NSFileManager defaultManager] fileExistsAtPath:localPath]) { NSLog(@"file is exist"); NSURL *fileurl=[NSURL URLWithString:localPath]; CKAsset *myfile=[[CKAsset alloc] initWithFileURL:fileurl]; //postRecrod[@"scriptPicture"]=myfile; [postRecrod setObject:myfile forKey:@"scriptPicture"]; } ”行中 错误信息如下:

  

由于未捕获的异常而终止应用   'NSInvalidArgumentException',原因:'非文件网址'

我不知道如何解决这个问题并整晚搜索网络,但没有任何帮助。 请帮我 !我是代码初学者!

2 个答案:

答案 0 :(得分:1)

您正在错误地构建fileurl

替换此行:

NSURL *fileurl=[NSURL URLWithString:localPath];

这一个:

NSURL *fileurl=[NSURL fileURLWithPath:localPath];

始终使用fileURLWithPath:方法从文件路径创建文件URL。在为表示以方案开头的正确URL(例如http:,mailto:等)的字符串创建URL时使用URLWithString:

答案 1 :(得分:0)

我认为你的字符串将以file://开头 您可以尝试将其更改为:

在斯威夫特:

A  B
1  Ud1
2  Ud1
3  Ud2
4  Ud2
5  Ud3
6  Ud3
.
.
.
相关问题