我正在尝试使用NSURL URLWithString从具有非常长的文件名的可能非常长的文件路径创建NSURL对象。当我使用URLWithString将文件路径转换为NSURL对象时,路径会缩短,并且在NSURL中加入省略号“...”:
Path as NSString: /var/mobile/Containers/Data/Application/APPLICATION_ID/Documents/TEMP/this_is_a_really_really_and_i_mean_reaeeeeaaaallly_long_file_name/this_is_a_really_really_and_i_mean_reaeeeeaaaallly_long_file_name.xml
// Convert to NSURL using this technique:
[NSURL URLWithString:pathAsString]
Path as NSUrl: /var/mobile/Containers/Data/Application/APPLICATION_ID/Documents/TEMP/this_is_a_really_really_and_ ... name.xml
我找不到解决此问题的任何方法,尝试在要创建的NSURL上打开文件时收到错误消息,说没有这样的文件或目录:
Error Domain=NSCocoaErrorDomain Code=260 "The operation couldn’t be completed. (Cocoa error 260.)" UserInfo=0x15ec82b0 {NSFilePath=/var/mobile/Containers/Data/Application/APPLICATION_ID/Documents/TEMP/this_is_a_really_really_and_ ... name.xml, NSUnderlyingError=0x15eac4a0 "The operation couldn’t be completed. No such file or directory"}
我不知道为什么要添加省略号,而且我不知道如何解决该问题。
最佳答案
您的密码
NSString *const path = @"/var/mobile/Containers/Data/Application/APPLICATION_ID/Documents/TEMP/this_is_a_really_really_and_i_mean_reaeeeeaaaallly_long_file_name/this_is_a_really_really_and_i_mean_reaeeeeaaaallly_long_file_name.xml";
NSURL *const url = [NSURL URLWithString:path];
NSLog(@"%@", url);
NSLog(@"%@", url.path);
版画
/var/mobile/Containers/Data/Application/APPLICATION_ID/Documents/TEMP/this_is_a_really_really_and_i_mean_reaeeeeaaaallly ... name.xml
/var/mobile/Containers/Data/Application/APPLICATION_ID/Documents/TEMP/this_is_a_really_really_and_i_mean_reaeeeeaaaallly_long_file_name/this_is_a_really_really_and_i_mean_reaeeeeaaaallly_long_file_name.xml
URL的路径已正确存储,
NSURL
s description
仅在记录URL时将其缩短。您的问题似乎出在其他地方。
关于ios - NSURL URLWithString正在用省略号“…”缩短很长的字符串,从而创建了无效的NSURL对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30764851/