1

到目前为止,我已经完成并在我的项目中实施了http://mobiforge.com/developing/story/importing-exporting-documents-ios 。然而,这无济于事。我试图让它在受支持的应用程序中打开任何文件。

我已经在我的 .h 和 .m 中声明了。

.h
UIDocumentInteractionController *documentController;
@property (retain) UIDocumentInteractionController *documentController;

.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [cellTapSound play];
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];

    [self openDocumentIn];

}

-(void)openDocumentIn {
    NSString * filePath = self.directoryPath = @"/var/mobile/Documents/downloads";
    documentController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
    documentController.delegate = self;
    [documentController retain];
    documentController.UTI = @"public.deb"  @"public.zip" @"public.text" @"com.apple.quicktime-movie" @"com.adobe.pdf";
    [documentController presentOpenInMenuFromRect:CGRectZero
                                           inView:self.view
                                         animated:YES];
}

-(void)documentInteractionController:(UIDocumentInteractionController *)controller
       willBeginSendingToApplication:(NSString *)application {

}

-(void)documentInteractionController:(UIDocumentInteractionController *)controller
          didEndSendingToApplication:(NSString *)application {

}

-(void)documentInteractionControllerDidDismissOpenInMenu:
(UIDocumentInteractionController *)controller {

}

任何帮助或指导将不胜感激。

更新 8/1

所以我设法让它工作,但唯一没有发生的事情是,无论我选择打开什么应用程序,它都不会显示文件。以 Dropbox 为例。下面是我更新的半工作代码。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [cellTapSound play];
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];


    NSString *filePath = [directoryContents objectAtIndex:indexPath.row];

    UIDocumentInteractionController *interactionController = [[UIDocumentInteractionController alloc] init];
    [interactionController setURL:[NSURL fileURLWithPath:filePath]];
    [interactionController setUTI:@"public.filename-extension"];

    [interactionController setDelegate:self];
    [interactionController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];


}

我想我需要在这里的某个地方声明一些东西,只是不知道是什么。

-(void)documentInteractionController:(UIDocumentInteractionController *)controller
       willBeginSendingToApplication:(NSString *)application {

}


-(void)documentInteractionController:(UIDocumentInteractionController *)controller
          didEndSendingToApplication:(NSString *)application {

}

又卡住了,有什么想法吗?

更新 8/6

出于愚蠢的愚蠢运气,我让它工作了:) 在下面发布了答案。

尽管这里没有人回答,但我希望这对其他人有所帮助。

4

1 回答 1

0

这是它为我工作的原因。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [cellTapSound play];
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];


    NSString *fileName = [directoryContents objectAtIndex:indexPath.row];

    NSString *path;
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"my downloads"];
    path = [path stringByAppendingPathComponent:fileName];

    documentController = [[UIDocumentInteractionController alloc] init];
    documentController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:path]];

    [documentController setDelegate:self];
    [documentController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
    [documentController retain];
}
于 2013-12-10T22:18:46.203 回答