Debian Codegraph @

drivers/apple_embedded/godot_app_delegate.mm

raw
1 /**************************************************************************/
2 /* godot_app_delegate.mm */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #import "godot_app_delegate.h"
32
33 #import "app_delegate_service.h"
34 #include "core/typedefs.h"
35
36 @implementation GDTApplicationDelegate
37
38 static NSMutableArray<GDTAppDelegateServiceProtocol *> *services = nil;
39
40 + (NSArray<GDTAppDelegateServiceProtocol *> *)services {
41 return services;
42 }
43
44 + (void)load {
45 services = [NSMutableArray new];
46 [services addObject:[GDTAppDelegateService new]];
47 }
48
49 + (void)addService:(GDTAppDelegateServiceProtocol *)service {
50 if (!services || !service) {
51 return;
52 }
53 [services addObject:service];
54 }
55
56 // UIApplicationDelegate documentation can be found here: https://developer.apple.com/documentation/uikit/uiapplicationdelegate
57
58 // MARK: Window
59
60 - (UIWindow *)window {
61 UIWindow *result = nil;
62
63 for (GDTAppDelegateServiceProtocol *service in services) {
64 if (![service respondsToSelector:_cmd]) {
65 continue;
66 }
67
68 UIWindow *value = [service window];
69
70 if (value) {
71 result = value;
72 }
73 }
74
75 return result;
76 }
77
78 // MARK: Initializing
79
80 - (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary<UIApplicationLaunchOptionsKey, id> *)launchOptions {
81 BOOL result = NO;
82
83 for (GDTAppDelegateServiceProtocol *service in services) {
84 if (![service respondsToSelector:_cmd]) {
85 continue;
86 }
87
88 if ([service application:application willFinishLaunchingWithOptions:launchOptions]) {
89 result = YES;
90 }
91 }
92
93 return result;
94 }
95
96 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary<UIApplicationLaunchOptionsKey, id> *)launchOptions {
97 BOOL result = NO;
98
99 for (GDTAppDelegateServiceProtocol *service in services) {
100 if (![service respondsToSelector:_cmd]) {
101 continue;
102 }
103
104 if ([service application:application didFinishLaunchingWithOptions:launchOptions]) {
105 result = YES;
106 }
107 }
108
109 return result;
110 }
111
112 // MARK: Scene
113
114 - (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options API_AVAILABLE(ios(13.0), tvos(13.0), visionos(1.0)) {
115 UISceneConfiguration *config = [[UISceneConfiguration alloc] initWithName:@"Default Configuration" sessionRole:connectingSceneSession.role];
116 config.delegateClass = [GDTApplicationDelegate class];
117 return config;
118 }
119
120 - (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet<UISceneSession *> *)sceneSessions API_AVAILABLE(ios(13.0), tvos(13.0), visionos(1.0)) {
121 }
122
123 // MARK: Life-Cycle
124
125 - (void)sceneDidDisconnect:(UIScene *)scene API_AVAILABLE(ios(13.0), tvos(13.0), visionos(1.0)) {
126 for (GDTAppDelegateServiceProtocol *service in services) {
127 if (![service respondsToSelector:_cmd]) {
128 continue;
129 }
130
131 [service sceneDidDisconnect:scene];
132 }
133 }
134
135 - (void)sceneDidBecomeActive:(UIScene *)scene API_AVAILABLE(ios(13.0), tvos(13.0), visionos(1.0)) {
136 for (GDTAppDelegateServiceProtocol *service in services) {
137 if (![service respondsToSelector:_cmd]) {
138 continue;
139 }
140
141 [service sceneDidBecomeActive:scene];
142 }
143 }
144
145 - (void)sceneWillResignActive:(UIScene *)scene API_AVAILABLE(ios(13.0), tvos(13.0), visionos(1.0)) {
146 for (GDTAppDelegateServiceProtocol *service in services) {
147 if (![service respondsToSelector:_cmd]) {
148 continue;
149 }
150
151 [service sceneWillResignActive:scene];
152 }
153 }
154
155 - (void)sceneDidEnterBackground:(UIScene *)scene API_AVAILABLE(ios(13.0), tvos(13.0), visionos(1.0)) {
156 for (GDTAppDelegateServiceProtocol *service in services) {
157 if (![service respondsToSelector:_cmd]) {
158 continue;
159 }
160
161 [service sceneDidEnterBackground:scene];
162 }
163 }
164
165 - (void)sceneWillEnterForeground:(UIScene *)scene API_AVAILABLE(ios(13.0), tvos(13.0), visionos(1.0)) {
166 for (GDTAppDelegateServiceProtocol *service in services) {
167 if (![service respondsToSelector:_cmd]) {
168 continue;
169 }
170
171 [service sceneWillEnterForeground:scene];
172 }
173 }
174
175 // UIApplication lifecycle has become deprecated in favor of UIScene lifecycle
176 GODOT_CLANG_WARNING_PUSH_AND_IGNORE("-Wdeprecated-declarations")
177
178 - (void)applicationDidBecomeActive:(UIApplication *)application {
179 for (GDTAppDelegateServiceProtocol *service in services) {
180 if (![service respondsToSelector:_cmd]) {
181 continue;
182 }
183
184 [service applicationDidBecomeActive:application];
185 }
186 }
187
188 - (void)applicationWillResignActive:(UIApplication *)application {
189 for (GDTAppDelegateServiceProtocol *service in services) {
190 if (![service respondsToSelector:_cmd]) {
191 continue;
192 }
193
194 [service applicationWillResignActive:application];
195 }
196 }
197
198 - (void)applicationDidEnterBackground:(UIApplication *)application {
199 for (GDTAppDelegateServiceProtocol *service in services) {
200 if (![service respondsToSelector:_cmd]) {
201 continue;
202 }
203
204 [service applicationDidEnterBackground:application];
205 }
206 }
207
208 - (void)applicationWillEnterForeground:(UIApplication *)application {
209 for (GDTAppDelegateServiceProtocol *service in services) {
210 if (![service respondsToSelector:_cmd]) {
211 continue;
212 }
213
214 [service applicationWillEnterForeground:application];
215 }
216 }
217
218 - (void)applicationWillTerminate:(UIApplication *)application {
219 for (GDTAppDelegateServiceProtocol *service in services) {
220 if (![service respondsToSelector:_cmd]) {
221 continue;
222 }
223
224 [service applicationWillTerminate:application];
225 }
226 }
227
228 // MARK: Environment Changes
229
230 - (void)applicationProtectedDataDidBecomeAvailable:(UIApplication *)application {
231 for (GDTAppDelegateServiceProtocol *service in services) {
232 if (![service respondsToSelector:_cmd]) {
233 continue;
234 }
235
236 [service applicationProtectedDataDidBecomeAvailable:application];
237 }
238 }
239
240 - (void)applicationProtectedDataWillBecomeUnavailable:(UIApplication *)application {
241 for (GDTAppDelegateServiceProtocol *service in services) {
242 if (![service respondsToSelector:_cmd]) {
243 continue;
244 }
245
246 [service applicationProtectedDataWillBecomeUnavailable:application];
247 }
248 }
249
250 - (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
251 for (GDTAppDelegateServiceProtocol *service in services) {
252 if (![service respondsToSelector:_cmd]) {
253 continue;
254 }
255
256 [service applicationDidReceiveMemoryWarning:application];
257 }
258 }
259
260 - (void)applicationSignificantTimeChange:(UIApplication *)application {
261 for (GDTAppDelegateServiceProtocol *service in services) {
262 if (![service respondsToSelector:_cmd]) {
263 continue;
264 }
265
266 [service applicationSignificantTimeChange:application];
267 }
268 }
269
270 // MARK: App State Restoration
271
272 - (BOOL)application:(UIApplication *)application shouldSaveSecureApplicationState:(NSCoder *)coder API_AVAILABLE(ios(13.2)) {
273 BOOL result = NO;
274
275 for (GDTAppDelegateServiceProtocol *service in services) {
276 if (![service respondsToSelector:_cmd]) {
277 continue;
278 }
279
280 if ([service application:application shouldSaveSecureApplicationState:coder]) {
281 result = YES;
282 }
283 }
284
285 return result;
286 }
287
288 - (BOOL)application:(UIApplication *)application shouldRestoreSecureApplicationState:(NSCoder *)coder API_AVAILABLE(ios(13.2)) {
289 BOOL result = NO;
290
291 for (GDTAppDelegateServiceProtocol *service in services) {
292 if (![service respondsToSelector:_cmd]) {
293 continue;
294 }
295
296 if ([service application:application shouldRestoreSecureApplicationState:coder]) {
297 result = YES;
298 }
299 }
300
301 return result;
302 }
303
304 - (UIViewController *)application:(UIApplication *)application viewControllerWithRestorationIdentifierPath:(NSArray<NSString *> *)identifierComponents coder:(NSCoder *)coder {
305 for (GDTAppDelegateServiceProtocol *service in services) {
306 if (![service respondsToSelector:_cmd]) {
307 continue;
308 }
309
310 UIViewController *controller = [service application:application viewControllerWithRestorationIdentifierPath:identifierComponents coder:coder];
311
312 if (controller) {
313 return controller;
314 }
315 }
316
317 return nil;
318 }
319
320 - (void)application:(UIApplication *)application willEncodeRestorableStateWithCoder:(NSCoder *)coder {
321 for (GDTAppDelegateServiceProtocol *service in services) {
322 if (![service respondsToSelector:_cmd]) {
323 continue;
324 }
325
326 [service application:application willEncodeRestorableStateWithCoder:coder];
327 }
328 }
329
330 - (void)application:(UIApplication *)application didDecodeRestorableStateWithCoder:(NSCoder *)coder {
331 for (GDTAppDelegateServiceProtocol *service in services) {
332 if (![service respondsToSelector:_cmd]) {
333 continue;
334 }
335
336 [service application:application didDecodeRestorableStateWithCoder:coder];
337 }
338 }
339
340 // MARK: Download Data in Background
341
342 - (void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier completionHandler:(void (^)(void))completionHandler {
343 for (GDTAppDelegateServiceProtocol *service in services) {
344 if (![service respondsToSelector:_cmd]) {
345 continue;
346 }
347
348 [service application:application handleEventsForBackgroundURLSession:identifier completionHandler:completionHandler];
349 }
350
351 completionHandler();
352 }
353
354 // MARK: Remote Notification
355
356 // Moved to the iOS Plugin
357
358 // MARK: User Activity and Handling Quick Actions
359
360 - (BOOL)application:(UIApplication *)application willContinueUserActivityWithType:(NSString *)userActivityType {
361 BOOL result = NO;
362
363 for (GDTAppDelegateServiceProtocol *service in services) {
364 if (![service respondsToSelector:_cmd]) {
365 continue;
366 }
367
368 if ([service application:application willContinueUserActivityWithType:userActivityType]) {
369 result = YES;
370 }
371 }
372
373 return result;
374 }
375
376 - (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> *restorableObjects))restorationHandler {
377 BOOL result = NO;
378
379 for (GDTAppDelegateServiceProtocol *service in services) {
380 if (![service respondsToSelector:_cmd]) {
381 continue;
382 }
383
384 if ([service application:application continueUserActivity:userActivity restorationHandler:restorationHandler]) {
385 result = YES;
386 }
387 }
388
389 return result;
390 }
391
392 - (void)application:(UIApplication *)application didUpdateUserActivity:(NSUserActivity *)userActivity {
393 for (GDTAppDelegateServiceProtocol *service in services) {
394 if (![service respondsToSelector:_cmd]) {
395 continue;
396 }
397
398 [service application:application didUpdateUserActivity:userActivity];
399 }
400 }
401
402 - (void)application:(UIApplication *)application didFailToContinueUserActivityWithType:(NSString *)userActivityType error:(NSError *)error {
403 for (GDTAppDelegateServiceProtocol *service in services) {
404 if (![service respondsToSelector:_cmd]) {
405 continue;
406 }
407
408 [service application:application didFailToContinueUserActivityWithType:userActivityType error:error];
409 }
410 }
411
412 - (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL succeeded))completionHandler {
413 for (GDTAppDelegateServiceProtocol *service in services) {
414 if (![service respondsToSelector:_cmd]) {
415 continue;
416 }
417
418 [service application:application performActionForShortcutItem:shortcutItem completionHandler:completionHandler];
419 }
420 }
421
422 // MARK: WatchKit
423
424 - (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void (^)(NSDictionary *replyInfo))reply {
425 for (GDTAppDelegateServiceProtocol *service in services) {
426 if (![service respondsToSelector:_cmd]) {
427 continue;
428 }
429
430 [service application:application handleWatchKitExtensionRequest:userInfo reply:reply];
431 }
432 }
433
434 // MARK: HealthKit
435
436 - (void)applicationShouldRequestHealthAuthorization:(UIApplication *)application {
437 for (GDTAppDelegateServiceProtocol *service in services) {
438 if (![service respondsToSelector:_cmd]) {
439 continue;
440 }
441
442 [service applicationShouldRequestHealthAuthorization:application];
443 }
444 }
445
446 // MARK: Opening an URL
447
448 - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options {
449 for (GDTAppDelegateServiceProtocol *service in services) {
450 if (![service respondsToSelector:_cmd]) {
451 continue;
452 }
453
454 if ([service application:app openURL:url options:options]) {
455 return YES;
456 }
457 }
458
459 return NO;
460 }
461
462 // MARK: Disallowing Specified App Extension Types
463
464 - (BOOL)application:(UIApplication *)application shouldAllowExtensionPointIdentifier:(UIApplicationExtensionPointIdentifier)extensionPointIdentifier {
465 BOOL result = NO;
466
467 for (GDTAppDelegateServiceProtocol *service in services) {
468 if (![service respondsToSelector:_cmd]) {
469 continue;
470 }
471
472 if ([service application:application shouldAllowExtensionPointIdentifier:extensionPointIdentifier]) {
473 result = YES;
474 }
475 }
476
477 return result;
478 }
479
480 // MARK: SiriKit
481
482 - (id)application:(UIApplication *)application handlerForIntent:(INIntent *)intent API_AVAILABLE(ios(14.0)) {
483 for (GDTAppDelegateServiceProtocol *service in services) {
484 if (![service respondsToSelector:_cmd]) {
485 continue;
486 }
487
488 id result = [service application:application handlerForIntent:intent];
489
490 if (result) {
491 return result;
492 }
493 }
494
495 return nil;
496 }
497
498 // MARK: CloudKit
499
500 - (void)application:(UIApplication *)application userDidAcceptCloudKitShareWithMetadata:(CKShareMetadata *)cloudKitShareMetadata {
501 for (GDTAppDelegateServiceProtocol *service in services) {
502 if (![service respondsToSelector:_cmd]) {
503 continue;
504 }
505
506 [service application:application userDidAcceptCloudKitShareWithMetadata:cloudKitShareMetadata];
507 }
508 }
509
510 /* Handled By Info.plist file for now
511
512 // MARK: Interface Geometry
513
514 - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {}
515
516 */
517
518 @end
519
520 GODOT_CLANG_WARNING_POP