diff options
Diffstat (limited to 'src/ios.m')
-rw-r--r-- | src/ios.m | 41 |
1 files changed, 40 insertions, 1 deletions
@@ -120,7 +120,9 @@ API_AVAILABLE(ios(13.0)) | |||
120 | 120 | ||
121 | /*----------------------------------------------------------------------------------------------*/ | 121 | /*----------------------------------------------------------------------------------------------*/ |
122 | 122 | ||
123 | @interface AppState : NSObject | 123 | @interface AppState : NSObject<UIDocumentPickerDelegate> { |
124 | iString *fileBeingSaved; | ||
125 | } | ||
124 | @property (nonatomic, assign) BOOL isHapticsAvailable; | 126 | @property (nonatomic, assign) BOOL isHapticsAvailable; |
125 | @property (nonatomic, strong) NSObject *haptic; | 127 | @property (nonatomic, strong) NSObject *haptic; |
126 | @end | 128 | @end |
@@ -129,6 +131,23 @@ static AppState *appState_; | |||
129 | 131 | ||
130 | @implementation AppState | 132 | @implementation AppState |
131 | 133 | ||
134 | -(instancetype)init { | ||
135 | self = [super init]; | ||
136 | fileBeingSaved = NULL; | ||
137 | return self; | ||
138 | } | ||
139 | |||
140 | -(void)setFileBeingSaved:(const iString *)path { | ||
141 | fileBeingSaved = copy_String(path); | ||
142 | } | ||
143 | |||
144 | -(void)removeSavedFile { | ||
145 | /* The file was copied to an external location, so the cached copy is not needed. */ | ||
146 | remove(cstr_String(fileBeingSaved)); | ||
147 | delete_String(fileBeingSaved); | ||
148 | fileBeingSaved = NULL; | ||
149 | } | ||
150 | |||
132 | -(void)setupHaptics { | 151 | -(void)setupHaptics { |
133 | if (@available(iOS 13.0, *)) { | 152 | if (@available(iOS 13.0, *)) { |
134 | self.isHapticsAvailable = CHHapticEngine.capabilitiesForHardware.supportsHaptics; | 153 | self.isHapticsAvailable = CHHapticEngine.capabilitiesForHardware.supportsHaptics; |
@@ -145,6 +164,15 @@ static AppState *appState_; | |||
145 | } | 164 | } |
146 | } | 165 | } |
147 | 166 | ||
167 | - (void)documentPicker:(UIDocumentPickerViewController *)controller | ||
168 | didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls { | ||
169 | [self removeSavedFile]; | ||
170 | } | ||
171 | |||
172 | - (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller { | ||
173 | [self removeSavedFile]; | ||
174 | } | ||
175 | |||
148 | -(void)keyboardOnScreen:(NSNotification *)notification { | 176 | -(void)keyboardOnScreen:(NSNotification *)notification { |
149 | NSDictionary *info = notification.userInfo; | 177 | NSDictionary *info = notification.userInfo; |
150 | NSValue *value = info[UIKeyboardFrameEndUserInfoKey]; | 178 | NSValue *value = info[UIKeyboardFrameEndUserInfoKey]; |
@@ -257,3 +285,14 @@ iBool processEvent_iOS(const SDL_Event *ev) { | |||
257 | } | 285 | } |
258 | return iFalse; /* allow normal processing */ | 286 | return iFalse; /* allow normal processing */ |
259 | } | 287 | } |
288 | |||
289 | void exportDownloadedFile_iOS(const iString *path) { | ||
290 | NSURL *url = [NSURL fileURLWithPath:[[NSString alloc] initWithCString:cstr_String(path) | ||
291 | encoding:NSUTF8StringEncoding]]; | ||
292 | UIDocumentPickerViewController *picker = [[UIDocumentPickerViewController alloc] | ||
293 | initWithURL:url | ||
294 | inMode:UIDocumentPickerModeExportToService]; | ||
295 | picker.delegate = appState_; | ||
296 | [appState_ setFileBeingSaved:path]; | ||
297 | [viewController_(get_Window()) presentViewController:picker animated:YES completion:nil]; | ||
298 | } | ||