ios - NSURL URLWithString正在用省略号“…”缩短很长的字符串,从而创建了无效的NSURL对象

标签 ios nsstring nsurl

我正在尝试使用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/

相关文章:

ios - CAShapeLayer 的 strokeEnd 上的 KVO

objective-c - 将数字格式化为字符串时,请删除整数

nsurlconnection - 在某些站点中,NSURLConnection 的 NSData 返回 NULL

swift - swift 3.0中跟踪一批HTTP请求的解决方案

ios - 代码 8 : Views not adjusting when UIElement is hidden

ios - Swift:在启动时显示登录屏幕时防止闪烁

ios - XCUITest 中的 Force Touch/3D Touch

objective-c - 我是否需要释放由 CFUUIDCreateString() 创建的 NSString?

objective-c - 字符串分离

ios - 如何找出 App Transport Security 阻止了哪些 HTTP 请求?