ios excel nsdata preview uidocumentinteraction

ios - UIDocumentInteractionController "esquema no válido(nulo)"



excel nsdata (1)

Estoy tratando de obtener una vista previa de un documento con UIDocumentInteractionController. El documento es un archivo .xls que mi aplicación descarga de la web. Sigo recibiendo este error:

''UIDocumentInteractionController: invalid scheme (null). Only the file scheme is supported.''

Yo uso el siguiente código:

- (void) webServiceController:(WebServiceController *)webServiceController returnedArray:(NSMutableArray *)array { if ([webServiceController.webRequest isEqualToString: @"generateExcelFileForEmployee"]) { // start previewing the document at the current section index NSString *link = [[NSString stringWithString:array[0]] stringByReplacingOccurrencesOfString:@"AdminFunctions.php" withString:@"AdminFunctions.xls"]; link = [[[link stringByReplacingOccurrencesOfString:@"//" withString:@""]stringByReplacingOccurrencesOfString:@"/public/sites/" withString:@"http://"]stringByReplacingOccurrencesOfString:@"/"///"" withString:@""]; NSLog(@"%@", link); NSData *urlData = [NSData dataWithContentsOfURL:[NSURL URLWithString:link]]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,@"AdminFunctions.xls"]; BOOL isWriteSuccess = [urlData writeToFile:filePath atomically:YES]; NSLog(@"%@", filePath); if(isWriteSuccess) //success { file = [NSURL fileURLWithPath:filePath]; self.fileView = [self setupControllerWithURL:file usingDelegate:self]; [self.fileView presentPreviewAnimated:YES]; } else { NSLog(@"file not written"); } } } - (UIDocumentInteractionController *) setupControllerWithURL: (NSURL*) fileURL usingDelegate: (id <UIDocumentInteractionControllerDelegate>) interactionDelegate { UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL: fileURL]; interactionController.delegate = interactionDelegate; return interactionController; } - (UIViewController *) documentInteractionControllerViewControllerForPreview: (UIDocumentInteractionController *) controller { return self; }

Ambos métodos se implementan en el viewcontroller en el que quiero presentar la vista previa. Sé con urlData que urlData los datos en el objeto urlData , porque cuando pongo puntos de interrupción, la consola dice que contiene 6144 bytes, que es exactamente el tamaño del documento para descargar.

He estado buscando esto por un rato tranquilo, pero parece que no puedo encontrar la manera de resolverlo. Ya intenté poner el objeto de link como fuente para el documentoControlador de interacción, pero luego el error cambia a:

''UIDocumentInteractionController: invalid scheme (http). Only the file scheme is supported.''

Cualquier comentario sobre cómo puedo superar este problema sería muy apreciado


Tratar de usar

file = [NSURL fileURLWithPath:filePath];

en lugar de

file = [NSURL URLWithString:filePath];