summaryrefslogtreecommitdiff
path: root/src/ios.m
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-06-11 12:39:28 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-06-11 12:39:28 +0300
commit31f7eafd9c6897cdf0ee7d6eeaade9dcc65cb006 (patch)
tree415707ca26c04ff1bee461c685e79c4302546cd4 /src/ios.m
parent703d2b41fa299a9f8e24a5f6064c3624c3dedbbb (diff)
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.
Diffstat (limited to 'src/ios.m')
-rw-r--r--src/ios.m26
1 files changed, 24 insertions, 2 deletions
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_;
181 181
182- (void)documentPicker:(UIDocumentPickerViewController *)controller 182- (void)documentPicker:(UIDocumentPickerViewController *)controller
183didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls { 183didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls {
184 [self removeSavedFile]; 184 if (fileBeingSaved) {
185 [self removeSavedFile];
186 }
187 else {
188 /* A file is being opened. */
189 NSURL *url = [urls firstObject];
190 iString *path = localFilePathFromUrl_String(collectNewCStr_String([[url absoluteString]
191 UTF8String]));
192 postCommandf_App("file.open temp:1 path:%s", cstrCollect_String(path));
193 }
185} 194}
186 195
187- (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller { 196- (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller {
188 [self removeSavedFile]; 197 if (fileBeingSaved) {
198 [self removeSavedFile];
199 }
189} 200}
190 201
191-(void)keyboardOnScreen:(NSNotification *)notification { 202-(void)keyboardOnScreen:(NSNotification *)notification {
@@ -335,6 +346,17 @@ void exportDownloadedFile_iOS(const iString *path) {
335 [viewController_(get_Window()) presentViewController:picker animated:YES completion:nil]; 346 [viewController_(get_Window()) presentViewController:picker animated:YES completion:nil];
336} 347}
337 348
349void pickFileForOpening_iOS(void) {
350 UIDocumentPickerViewController *picker = [[UIDocumentPickerViewController alloc]
351 initWithDocumentTypes:@[@"fi.skyjake.lagrange.gemini",
352 @"public.text",
353 @"public.image",
354 @"public.audio"]
355 inMode:UIDocumentPickerModeImport];
356 picker.delegate = appState_;
357 [viewController_(get_Window()) presentViewController:picker animated:YES completion:nil];
358}
359
338/*----------------------------------------------------------------------------------------------*/ 360/*----------------------------------------------------------------------------------------------*/
339 361
340enum iAVFAudioPlayerState { 362enum iAVFAudioPlayerState {