如何在 didFinishLaunchingWithOptions 中处理 unicode 文件路径
我正在开发一个支持查看文档文件的应用程序。问题是我有一个名称为乌尔都语的文件。
当我从邮件应用程序中选择“在 MyApp 中打开”选项时,该文件将被复制到“收件箱”文件夹中。我想将此文件复制到其他文件夹。我从 launchOption 字典获取文件路径并将其传递给 copyItemAt 方法。获取文件路径的代码是
NSURL *url = (NSURL *)[launchOptions valueForKey:UIApplicationLaunchOptionsURLKey];
NSString *urlStr = [url absoluteString];
复制文件的代码是
[[NSFileManager defaultManager] copyItemAtPath:urlStr toPath:destPath error:&error]
但它返回错误“没有这样的文件或目录”。我已经检查过,该文件已正确放置在收件箱文件夹中,其名称为乌尔都语。
请帮忙。 此致
I am developing an app which supports viewing of document files. Problem is that I have a file whose name is in Urdu language.
When I select "Open in MyApp" option from Mail app, the file is copied into Inbox folder. I want to copy this file to some other folder. I get the file path from launchOption dictionary and pass it to copyItemAt method. Code for getting file path is
NSURL *url = (NSURL *)[launchOptions valueForKey:UIApplicationLaunchOptionsURLKey];
NSString *urlStr = [url absoluteString];
And code for copying the file is
[[NSFileManager defaultManager] copyItemAtPath:urlStr toPath:destPath error:&error]
But it returns the error "No such file or directory." I have checked and the file is placed correctly in the Inbox folder with its name in Urdu language.
Kindly help.
Best Regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常,路径的格式为
/../.../filename.extension
,文件 URL 的格式为file://../.../filename.extension< /代码>。当您使用
absoluteString
时,您将获得与字符串相同的file://../.../filename.extension
。您应该改为向path
发送消息。Usually, paths are of the form
/../.../filename.extension
and file URLs are of the formfile://../.../filename.extension
. When you useabsoluteString
, you will get the samefile://../.../filename.extension
as a string. You should message itpath
instead.