调用addAttachmentData时如何从附件中删除路径? [英] How to remove the path from an attachment when calling addAttachmentData?

查看:96
本文介绍了调用addAttachmentData时如何从附件中删除路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将附件添加到电子邮件时,文件名将获得其完整路径.

When adding an attachment to an email, the file name gets it's complete path.

对于位于以下位置的文件:

For a file located in:

/var/mobile/Applications/C3BBAA5F-07FE-4E26-9661-CB492E06BD2E/Documents/

结果是,我得到一个名为:

I'm getting as a result, a file named:

_var_mobile_Applications_C3BBAA5F-07FE-4E26-9661-CB492E06BD2E_Documents_Clock.sqlite

当我需要输入文件名时:

When I need my filename to be:

Clock.sqlite

这是我的代码:

NSString *path = [self getDatabaseFilePath];
NSData *myData = [NSData dataWithContentsOfFile:path];
[picker addAttachmentData:myData mimeType:@"application/x-sqlite3" fileName:path];

如何使附件仅具有文件名和扩展名,而没有完整路径?

How can I get the attachment to have only the filename and extension, without the complete path?

谢谢!

推荐答案

这应该做您想要的:

NSString *path = [self getDatabaseFilePath];
NSData *myData = [NSData dataWithContentsOfFile:path];
[picker addAttachmentData:myData mimeType:@"application/x-sqlite3" fileName:[path lastPathComponent]];

这篇关于调用addAttachmentData时如何从附件中删除路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆