From 31f7eafd9c6897cdf0ee7d6eeaade9dcc65cb006 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Fri, 11 Jun 2021 12:39:28 +0300 Subject: iOS: Opening a file via document picker Use a native file picker to open files. Declare support for .gmi/.gemini files so they can be opened via Files and share sheets. --- src/ios.m | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'src/ios.m') diff --git a/src/ios.m b/src/ios.m index a1654df2..e7288677 100644 --- a/src/ios.m +++ b/src/ios.m @@ -181,11 +181,22 @@ static AppState *appState_; - (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray *)urls { - [self removeSavedFile]; + if (fileBeingSaved) { + [self removeSavedFile]; + } + else { + /* A file is being opened. */ + NSURL *url = [urls firstObject]; + iString *path = localFilePathFromUrl_String(collectNewCStr_String([[url absoluteString] + UTF8String])); + postCommandf_App("file.open temp:1 path:%s", cstrCollect_String(path)); + } } - (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller { - [self removeSavedFile]; + if (fileBeingSaved) { + [self removeSavedFile]; + } } -(void)keyboardOnScreen:(NSNotification *)notification { @@ -335,6 +346,17 @@ void exportDownloadedFile_iOS(const iString *path) { [viewController_(get_Window()) presentViewController:picker animated:YES completion:nil]; } +void pickFileForOpening_iOS(void) { + UIDocumentPickerViewController *picker = [[UIDocumentPickerViewController alloc] + initWithDocumentTypes:@[@"fi.skyjake.lagrange.gemini", + @"public.text", + @"public.image", + @"public.audio"] + inMode:UIDocumentPickerModeImport]; + picker.delegate = appState_; + [viewController_(get_Window()) presentViewController:picker animated:YES completion:nil]; +} + /*----------------------------------------------------------------------------------------------*/ enum iAVFAudioPlayerState { -- cgit v1.2.3