在我下面的代码中,
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"];
}错误将发生在"CKAsset *myfile=[[CKAsset alloc] initWithFileURL:fileurl];“错误消息如下:
由于“NSInvalidArgumentException”异常终止应用程序,原因:“非文件URL”
我不知道如何解决这个问题,整夜搜索网页,但没有帮助。请救救我!我是个代码初学者!
发布于 2016-01-12 08:02:30
您正在错误地构建fileurl。
替换这一行:
NSURL *fileurl=[NSURL URLWithString:localPath];有了这个:
NSURL *fileurl=[NSURL fileURLWithPath:localPath];始终使用fileURLWithPath:方法从文件路径创建文件URL。在为以方案开头的字符串创建URL时使用URLWithString: (如http:、mailto:等)。
发布于 2016-01-11 08:51:13
我认为您的字符串将以file://开始,您是否可以尝试将其更改为如下所示:
在Swift:
CKAsset(fileURL: NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("temporary", ofType: "png")!))https://stackoverflow.com/questions/34701898
复制相似问题