Tag: nsdocumentdirectory

MPMoviePlayerController不能从Documents文件夹中播放

Desperated。 大家好! 我有一些与MPMoviePlayerController问题。 我已经使用NSBundle的video。 但那不是我所需要的。 我需要从Documents目录播放它,因为那是我存储录制video的地方,这些URL存储在CoreData中。 但是让我们把它放在一边,简化代码到最小的需要。 这个代码实际上是工作如果使用contentURL,导致NSBundle。 之后,我做了什么去文档的地方。 我做的事: NSURL *contentURL = [[NSBundle mainBundle] URLForResource:@"Oct_08_2012_10_00_51" withExtension:@"mp4"]; // this works NSString* docPath = [NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSString * docaPathFull = [NSString stringWithFormat:@"%@%@", docPath, @"/Oct_08_2012_10_00_51.mp4"]; NSURL * docUrl= [NSURL URLWithString: docaPathFull]; BOOL ex = [[NSFileManager defaultManager] fileExistsAtPath:docaPathFull]; NSLog(@"file exists: %d, path using docPath: %@",ex, […]

文件从NSLibraryDirectory中消失

我正在iOS应用程序的库目录中存储一些文件,使用以下方法来构build它。 最后,我可以调用[MyClass dataDirectory]来处理文件,一切正常。 不过,我最近发现,有些文件似乎正在神秘地消失在这个目录之外。 根据文件 ,这不应该是这样的。 这是一个安全的地方来存储持久性文件? 该目录的控制台输出是: ~/var/mobile/Containers/Data/Application/{id}/Library/Data + (NSString*)libraryDirectory { return [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) lastObject]; } + (NSString*)dataDirectory { NSString* dir = [[self libraryDirectory] stringByAppendingPathComponent:@"Data"]; BOOL isDir=NO; NSError * error = nil; NSFileManager *fileManager = [NSFileManager new]; if (![fileManager fileExistsAtPath:dir isDirectory:&isDir] && isDir) { [[NSFileManager defaultManager] createDirectoryAtPath:dir withIntermediateDirectories:YES attributes:nil error:&error]; } [self addSkipBackupAttributeToItemAtURL:[NSURL […]

如何从iPhone中的文档目录中读取pdf文件?

目前我在iPhone应用程序工作,我有一个pdf文件在资源文件夹(本地pdf文件),然后我读了pdf文件(paper.pdf)成功,下面我提到读本地pdf文件供您参考。 例: CFURLRef pdfURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("paper.pdf"), NULL, NULL); pdf = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL); CFRelease(pdfURL); 然后我试图将pdf文件(从URL)存储在NSDocument目录中,成功存储。 NSData *pdfData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://www.msy.com.au/Parts/PARTS.pdf"]]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"myPDF11.pdf"]; [pdfData writeToFile:filePath atomically:YES]; 然后我试图读取该pdf文件(从NSDocument目录),但我不知道,请帮助我。 提前致谢

iPhone SDK Xcode – 如何获取文档目录中的所有文件名

我想获取我的应用程序的documents文件夹中的所有文件名,并将它们放在一个NSMutableArray 。 没有什么比这更less的了。

将数组保存到包含自定义对象iPhone的Plist文件

我有一个名为XYZinheritance自NSObject的类和一个包含XYZ对象的数组。 我需要将这个数组写入文档目录的plist文件。 在尝试[array writeToFile ….]之后,我发现writeToFile失败,因为数组包含XYZ类的自定义对象。 可能的解决scheme是将对象转换为NSData。 有什么不同的方式来实现这个? 我发现NSCoding是合适的,但不能理解如何使用它。 任何帮助将不胜感激。

在NSDocumentDirectory上禁用数据备份时CFURLSetResourcePropertyForKey失败

我正试图下载图像文件并存储在NSDocumentDirectory 。 为了做到这一点,我必须closuresiCloud和iTunes上的数据备份。 以下是我的代码: +(void)saveData:(NSData*)thedata:(NSString*)fileName { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *localFilePath = [documentsDirectory stringByAppendingPathComponent:fileName]; NSFileManager *fileManager = [NSFileManager defaultManager]; [fileManager createFileAtPath:localFilePath contents:thedata attributes:nil]; //prevent files from backup on iCloud or iTune NSURL *fileURL = [NSURL URLWithString:localFilePath]; [self addSkipBackupAttributeToItemAtURL:fileURL]; } 和我的addskipbackupattributetoitematurl: +(BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)fileURL { if (![[NSFileManager defaultManager] fileExistsAtPath:[fileURL […]

在SKPSMTPMessage中附加一个video

我有我的应用程序中存储在我的文档目录中的VideoClip.mp4。 我可以用SKPSMTPMessage(电子邮件,主题,正文等)成功发送电子邮件,但是我无法连接video。 我已经搜查了很多,但我会继续寻找。 如果有人能帮助我,那将非常感激。 谢谢! 这个代码(显然)附加了一个图像,但我一直无法弄清楚如何操作它来附加video: NSString *image_path = [[NSBundle mainBundle] pathForResource:@\"Success\" ofType:@\"png\"]; NSData *image_data = [NSData dataWithContentsOfFile:image_path]; NSDictionary *image_part = [NSDictionary dictionaryWithObjectsAndKeys: @\"inline;\r\n\tfilename=\\"Success.png\\"\",kSKPSMTPPartContentDispositionKey, @\"base64\",kSKPSMTPPartContentTransferEncodingKey, @\"image/png;\r\n\tname=Success.png;\r\n\tx-unix-mode=0666\",kSKPSMTPPartContentTypeKey, [image_data encodeWrappedBase64ForData],kSKPSMTPPartMessageKey, nil];

使用Cocoa-Touch从文档目录播放下载的video

我试图让我的应用程序播放已下载到文档目录的video文件。 我知道该文件正在下载,但我似乎无法获得文件播放,这里是我的代码: -(IBAction)play{ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *path = [documentsDirectory stringByAppendingPathComponent:@"%@/piggy.m4v"]; NSURL *movieURL = [NSURL fileURLWithPath:path]; _player = [[MPMoviePlayerController alloc] initWithContentURL:movieURL]; [self.view addSubview:_player.view]; _player.controlStyle = MPMovieControlStyleDefault; _player.shouldAutoplay = YES; [_player setFullscreen:YES animated:YES]; [_player play]; }

NSSearchPathForDirectoriesInDomains返回错误的目录

我正在使用NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)来获取我的应用程序中的应用程序文档目录,但返回的数组只包含一个对象,它是一个不可写的,不正确的目录: /用户/我/库/应用程序支持/ iPhone模拟器/文档 我发现这个问题表明这个问题与供应有关,但是答案只是说明了这一点。 所以我想我在问一个重复的问题,但是这个问题的答案是不够的,所以我希望在这个问题上得到一个真正的答案。

从文档目录内的目录中删除文件?

我创build了一个Temp目录来存储一些文件: //MARK: -create save delete from directory func createTempDirectoryToStoreFile(){ var error: NSError? let paths = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true) let documentsDirectory: AnyObject = paths[0] tempPath = documentsDirectory.stringByAppendingPathComponent("Temp") if (!NSFileManager.defaultManager().fileExistsAtPath(tempPath!)) { NSFileManager.defaultManager() .createDirectoryAtPath(tempPath!, withIntermediateDirectories: false, attributes: nil, error: &error) } } 这很好,现在我想删除目录中的所有文件…我试着如下: func clearAllFilesFromTempDirectory(){ var error: NSErrorPointer = nil let dirPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as! String […]