我无法弄清楚为什么Mac Pro上的xcode 6.1(6A1052d)在MacBook Pro上对待NSURL与Xcode 6.1(6A3117)不同。实施例
的MacPro:
if ( [[pb types] containsObject:NSURLPboardType] ) {
NSURL *fileURL = [NSURL URLFromPasteboard:pb];
NSLog(@"fileURL Drop %@", fileURL);
}
return NSDragOperationCopy;
OUTPUT:fileURL删除文件:///.file/id = 6571367.27666129
MacBook Pro:
if ( [[pb types] containsObject:NSURLPboardType] ) {
NSURL *fileURL = [NSURL URLFromPasteboard:pb];
NSLog(@"fileURL Drop %@", fileURL);
}
return NSDragOperationCopy;
OUTPUT:fileURL Drop file:///Users/su.../Desktop/Hardsoul%20feat.%20Candy%20Dulfer%20-%20Lust%20For%20Life%20(Hardsoul%20Mix).mp3 ...
正如您所看到的,相同的方法将不同的URL返回为普通URL,将其他URL返回为文件ID。所以请帮助理解发生的事情。通常我在同一个项目中使用两个不同的mac ...一次一个。
答案 0 :(得分:1)
//我正在使用Apple Docu Sample:从nsurl中提取文件名 //改为此
if ([[[sender draggingPasteboard] types] containsObject:NSFilenamesPboardType])
{
NSArray *files = [[sender draggingPasteboard] propertyListForType:NSFilenamesPboardType];
pathOfDraggedImage = [files objectAtIndex:0];
pathOfDraggedImage = [pathOfDraggedImage lastPathComponent];
pathOfDraggedImage = [pathOfDraggedImage stringByReplacingOccurrencesOfString:@"%20" withString:@"_"];
if ([pathOfDraggedImage length] > 70) {
// only take 70 characters
pathOfDraggedImage = [pathOfDraggedImage substringWithRange: NSMakeRange(0, 70)];
}
}