Tag: nsfilemanager

如何显示文件从Swift共享文件3

在我的应用程序的Plist中添加文件共享所以,我可以轻松地复制文件时,iPhone已经连接到iTunes到我的Mac但问题是,当我复制一些文件与iTunes中的应用程序和运行应用程序我有2个问题: 1-当我停止应用程序,再次打开,我不能看到任何文件在iTunes中的文件共享部分 2-这个代码下面这里应该打印文件存在,如果有文件,并打印一些东西,如果没有文件但只是打印文件存在 这里是我的代码 if filemgr.fileExists(atPath: "/Applications") { print("File exists") } else { print("File not found") } 当我点击button来检查文件,我只是看到文件存在即使当我删除的应用程序,并再次安装,请帮助我

iOS – 将audio文件保存到iTunes音乐库

我正在一个audio应用程序,我需要问用户他/她是否希望保存录音。 现在我的问题是我应该在哪里保存这个文件。 直到现在,我GOOGLE了这一点,发现苹果不会允许写在沙箱外面。 在文档目录中写入大文件可能会导致应用程序拒绝。 所以任何人遇到同样的问题,请分享解决scheme。 参考: iOS:保存在iTunes资料库中可见的audio文件

尝试复制文件时出错

我想使用NSFileManager复制临时文件到另一个位置。 然而,这是失败的抱怨,其中一个文件不存在。 //Copy temp file NSError *error; BOOL exists = [fileManager fileExistsAtPath:chapterFileTemp]; exists = [fileManager fileExistsAtPath:chapterFile]; [fileManager copyItemAtURL:[NSURL fileURLWithPath:chapterFileTemp] toURL:[NSURL fileURLWithPath:chapterFile] error:&error]; //Delete temp path [fileManager removeItemAtURL:[NSURL fileURLWithPath:chapterFileTemp] error:&error]; 我在复制操作时出错 (错误域= NSCocoaErrorDomain代码= 260“操作无法完成(Cocoa错误260.)”UserInfo = 0x1c5190b0 {NSFilePath = / var / mobile / Applications / 57727CCD-88AD-4D84-8C78-EA8100645C9B / Documents / 119 /myFileTemp.temp,NSUnderlyingError = 0x1c527960“操作无法完成,没有这样的文件或目录”)。 现在第一个BOOL返回YES,第二个NO。 这是预期的。 什么可能是失败的原因 […]

cachingFacebook个人资料图片iOS

我正在将图片保存到磁盘,以供我的应用用户使用,他们要么上传图片,要么与Facebook连接,然后显示他们的个人资料图片。 这很好,但如果用户更改他们的脸谱资料图片,下面的代码永远不会更新图像。 我怎样才能检查facebook graph api检查是否已经上传图像没有重新下载图像? 我正在使用AFNetworking所以检查302头是一个选项,如果可能 – 只是不知道如何实现。 //load image if exists on disk NSFileManager *fileManager = [NSFileManager defaultManager]; NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]; NSString *filePath = [documentsPath stringByAppendingPathComponent:uniqueCustomerPath]; BOOL fileExists = [fileManager fileExistsAtPath:filePath]; if(fileExists){ UIImage* tempImage = [UIImage imageWithContentsOfFile:filePath]; completionHandler(tempImage); } //download image if not else{ NSString *imageUrl=[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large", (long)self.customer.facebook_id]; UIImage *tempImage […]

创build目录时出现“没有这样的文件或目录”错误

我试图将用户生成的照片的缩略图保存在文档目录的子目录中,但是我无法首先创build子目录。 当我试图在文档目录中创build子目录时,我得到这个错误(没有这样的文件或目录): Error Domain=NSCocoaErrorDomain Code=4 "The operation couldn't be completed. (Cocoa error 4.)" UserInfo=0x17ef9c90 {NSFilePath=/var/mobile/Applications/FD0CC480-97FE-4E50-931F-5341DB6AD92B/Documents/com.Jonathan.App-Name/707F0431-7A09-4D33-B122-13C48AD4CA53, NSUnderlyingError=0x17e51520 "The operation couldn't be completed. No such file or directory"} 我很困惑。 我知道目录不存在,因为我试图创build它! 我唯一能想到的是文档目录是不正确的,但是从苹果文档中直接得知。 我不正确地尝试创build子目录? – (NSURL *)documentsDirectory { NSFileManager *sharedFM = [NSFileManager defaultManager]; NSArray *possibleURLs = [sharedFM URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask]; NSURL *appSupportDir = nil; NSURL *appDirectory = nil; if ([possibleURLs […]

在多个swift应用程序间共享数据库

我需要能够有3个迅速的应用程序,可以相互沟通。 将应用程序1视为与服务器通信并将信息存储在本地数据库中的基本应用程序,应用程序2和3需要读取(并可写入)应用程序1中创build的数据库。 在networking上看,这似乎是可能的'应用程序组'。如果所有3个应用程序在同一个应用程序组下,他们会自动有一个'共享文件夹',我可以创build和/或存储一个Realm DB? 应用程序2和3会使用NSFileManager与这个共享文件进行交互吗? 我似乎无法find任何这方面的例子。

NSFileManager的URL与path

为什么像moveItemAtURL:toURL:error:这样的path方法推荐使用像moveItemAtURL:toURL:error: of NSFileManager类的URL方法moveItemAtPath:toPath:error:

NSFileManager创build目录错误518 NSFileWriteUnsupportedSchemeError

我正在尝试创build一个目录 NSError*error=nil; NSString* BIDirectory=[[NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask,YES) objectAtIndex:0] stringByAppendingPathComponent:@"BI"]; BOOL isDir,flag=YES; //if the directory doesn't exist create it. if(!([[NSFileManager defaultManager] fileExistsAtPath:BIDirectory isDirectory:&isDir]&& isDir)) flag=[[NSFileManager defaultManager] createDirectoryAtURL:[NSURL URLWithString:BIDirectory] withIntermediateDirectories:YES attributes:nil error:&error]; 我得到了以下错误 enter code hereError Domain=NSCocoaErrorDomain Code=518 "The operation couldn't be completed. (Cocoa error 518.)" UserInfo=0x197190 {NSURL=/var/mobile/Applications/55793654-6CDB-4B07-8FBF-553DC37D583D/Library/Caches/BI} 也许这个url是错的?

从数据库永久删除文件ios

我正在制作一个录音机(m4a扩展文件)。 我正在为logging的文件的输出(在目录中)给出一个特定的URL。 我可以播放它,保存文件在数据库中的path,并可以稍后检索。 事情正在好转。 但我无法删除保存/未保存的文件。 每次录制audio时,文件都占用一个永久空间。 我无法删除它们。 我试过了互联网(stackoverflow of course)。 我有像这样的链接: 我有videourl,并希望使用此URl从iPhone中删除它 但他们正在显示COCOA错误4,当我尝试删除它们使用这样的代码:[[NSFileManager defaultManager] removeItemAtPath:strPath error:&error]; 请build议,并回复

在iPhone中将文件下载到文件夹

我是新来的iPhone, 我做了应用程序,当用户下载任何东西时,它被下载到DocumentDirectory 我想要在我在DocumentDirectory创build的DocumentDirectory夹中下载 如何做到这一点? 我以为我会下载文件到我的DocumentDirectory ,我将该文件移动到DocumentDirectory中的文件夹。 这是好的做法吗? 这是我的代码片段,但仍然无法移动我的文件。 – (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType { NSString *file = [NSString stringWithString:[url absoluteString]]; NSURL *fileURL = [NSURL URLWithString:file]; NSURLRequest *req = [NSURLRequest requestWithURL:fileURL]; [NSURLConnection connectionWithRequest:req delegate:self]; NSString *DestPath=[[[SourcePath stringByAppendingString:@"/"]stringByAppendingString:BookCateg]stringByAppendingString:@"/"]; if ([fm copyItemAtPath:SourcePath toPath:DestPath error:&error]) { NSLog(@"Success !"); } else{ NSLog(@"Fail to Move!"); } } 我的日志显示Fail to Move! 任何帮助将不胜感激。