Я пытаюсь просмотреть документ с помощью UIDocumentInteractionController. Документ представляет собой файл .xls, который загружает мое приложение из Интернета. Я получаю эту ошибку:UIDocumentInteractionController «неверная схема (null)»
'UIDocumentInteractionController: invalid scheme (null). Only the file scheme is supported.'
Я использую следующий код:
- (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;
}
Оба метода реализованы в ViewController, в котором я хочу представить предварительный просмотр. Я знаю, что жестко получаю данные в объекте urlData
, потому что, когда я помещаю точки останова, консоль говорит, что она содержит 6144 байта, что является точно размером загружаемого документа.
Я искал это для тишины сейчас, но я не могу понять, как это решить. Я уже пытался положить в link
объекта в качестве источника для documentInteractionController, но потом ошибка изменяется на:
'UIDocumentInteractionController: invalid scheme (http). Only the file scheme is supported.'
Любые комментарии о том, как я могу решить эту проблему будет высоко оценен
вы проверили, что п ile написано успешно или нет, поскольку вы используете тот же путь к файлу в UIDocumentInteractionController? –
Единственный способ, который я проверил, это nslogging путь к файлу, но на самом деле это не говорит, хранит ли файл? Теперь это первый раз для меня, чтобы реализовать контроллер взаимодействия с документом, поэтому не могли бы вы объяснить, как это проверить? – Joris416
Я редактировал ваш вопрос с добавлением vaidation для файла, написанного успешно или нет. Теперь замените его и попробуйте, что произойдет ??? –