How to remove the path from an attachment when calling addAttachmentData?

梦想的初衷 提交于 2019-12-11 08:56:14

问题


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

Here's my code:

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?

Thank you!


回答1:


This should do what you want:

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


来源:https://stackoverflow.com/questions/18286740/how-to-remove-the-path-from-an-attachment-when-calling-addattachmentdata

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!