Has*_*ian 53 cocoa objective-c nsbundle ios
我尝试获取名为"temp.pdf"的文件的文件路径,该文件位于NSTemporaryDirectory文件夹中(我已检查过,文件存在).
我用这个:
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"temp" ofType:@"pdf" inDirectory:NSTemporaryDirectory()];
Run Code Online (Sandbox Code Playgroud)
我尝试过:
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"temp.pdf" ofType:@"" inDirectory:NSTemporaryDirectory()];
Run Code Online (Sandbox Code Playgroud)
而且:
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"temp" ofType:@"pdf"];
Run Code Online (Sandbox Code Playgroud)
但似乎它不起作用,返回值始终为null.
所以,我有点困惑,有人可以帮助我吗?
谢谢.
Joe*_*Joe 125
NSTemporaryDirectory()提供临时目录的完整路径.而不是使用mainBundle你的尝试
NSString *filePath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"temp.pdf"];
Run Code Online (Sandbox Code Playgroud)
如果您需要URL,请执行以下操作:
NSURL *furl = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"temp.pdf"]];
Run Code Online (Sandbox Code Playgroud)
twt*_*wtr 13
Swift 2.0
let tmpDirURL = NSURL.fileURLWithPath(NSTemporaryDirectory(),isDirectory: true)
let fileURL = tmpDirURL.URLByAppendingPathComponent("stuff").URLByAppendingPathExtension("gif")
print("FilePath: \(fileURL.path)")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
55208 次 |
| 最近记录: |