从其他应用程序打开文件到我的应用程序后删除收件箱文件夹

时间:2014-08-02 15:42:43

标签: ios objective-c ios7 nsfilemanager

我已经使用此代码通过openin菜单打开从其他应用程序导入的其他文件 但问题是,当我尝试在导入文件后删除框文件夹时,它会给我许可错误

   -(void)openImportedFile:(NSURL *)url{

    NSFileManager *filemanager=[NSFileManager defaultManager];
    NSString *strfilepath=[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0];
    NSString *inboxPath=[strfilepath stringByAppendingPathComponent:@"NewDocument"];
    [filemanager createDirectoryAtPath:inboxPath withIntermediateDirectories:TRUE attributes:nil error:nil];
    NSString *strInboxFilepath=[url path];
    NSString *strdesPath=[inboxPath stringByAppendingPathComponent:[strInboxFilepath lastPathComponent]];
    [self performSelector:@selector(deleteInboxFolder) withObject:nil afterDelay:0.5];

    self.docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:strdesPath]];
    self.docController.delegate = self;
    [self.docController presentPreviewAnimated:YES];

    }

这是删除收件箱文件夹的代码

 -(void)deleteInboxFolder
    {
        NSFileManager *fm=[NSFileManager defaultManager];
        NSError *error;
 NSString *strfilepath=[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0];
        NSString *path = [NSString stringWithFormat:@"%@/Inbox",strfilepath];
        [fm removeItemAtPath:path error:&error];
        if(error){
            NSLog(@"%@",error);
        }

    }

我收到以下错误

Error Domain=NSCocoaErrorDomain Code=513 "The operation couldn’t be completed. (Cocoa error 513.)" UserInfo=0x16d5e7f0 {NSUnderlyingError=0x16d5e6d0 "The operation couldn’t be completed. Operation not permitted", NSFilePath=/var/mobile/Applications/D1252FCA-A496-45EE-80FC-4F6692AF4545/Documents/Inbox, NSUserStringVariant=(
    Remove
)}

我很困惑该怎么做 请建议我解决方案 在此先感谢

1 个答案:

答案 0 :(得分:0)

此目录似乎无法删除,因为它是从系统创建的,您无权这样做。 虽然没有明确说明,但docs给你至少一个提示。