到目前为止,我已经完成并将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
出于愚蠢的运气,我得到了它的工作:)发表以下答案。
虽然没有人在这里回答,但我希望这有助于其他人。
答案 0 :(得分: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];
}