UIDocumentInteractionController presentPreviewAnimated: returning NO and not showing preview
I've tried everything I can think of and it still responds NO and Apple's doesn't have any hints.
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"finished!");
开发者_StackOverflow社区NSString *tempString = [NSString stringWithFormat:@"file://%@%@", NSTemporaryDirectory(), [[NSProcessInfo processInfo] globallyUniqueString]];
NSURL *tempURL = [NSURL URLWithString:tempString];
[receivedData writeToURL:tempURL atomically:YES];
NSLog(@"tempURL is written!");
UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL:tempURL];
interactionController.delegate = self;
[interactionController retain];
NSLog(@"--- %i", [interactionController presentPreviewAnimated:YES]);
NSLog(@"presented preview");
[connection release];
[receivedData release];
}
- (UIViewController*)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller
{
NSLog(@"asdf");
UIViewController *viewController = [[[UIViewController alloc] init] autorelease];
[self.navigationController pushViewController:viewController animated:YES];
return viewController;
}
1) are you confident the document you're opening is kosher? If not, then returning NO would be the thing to expect
2) I'm puzzled by your delegate method. The present method is happy to do the pushing onto the navigation controller all by itself. Do you fair any better if you use this code instead? (See the docs for rationale.)
- (UIViewController *) documentInteractionControllerViewControllerForPreview: (UIDocumentInteractionController *) controller
{
return [self navigationController];
}
I had a similar issue with presentPreviewAnimated which returned NO. In my case I was missing an extension of the file. When I renamed my file from document to document.xlsx it was opened successfully.
精彩评论