godot_app_delegate.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. /**************************************************************************/
  2. /* godot_app_delegate.m */
  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. #import "godot_app_delegate.h"
  31. #import "app_delegate.h"
  32. @interface GodotApplicationDelegate ()
  33. @end
  34. @implementation GodotApplicationDelegate
  35. static NSMutableArray<ApplicationDelegateService *> *services = nil;
  36. + (NSArray<ApplicationDelegateService *> *)services {
  37. return services;
  38. }
  39. + (void)load {
  40. services = [NSMutableArray new];
  41. [services addObject:[AppDelegate new]];
  42. }
  43. + (void)addService:(ApplicationDelegateService *)service {
  44. if (!services || !service) {
  45. return;
  46. }
  47. [services addObject:service];
  48. }
  49. // UIApplicationDelegate documentation can be found here: https://developer.apple.com/documentation/uikit/uiapplicationdelegate
  50. // MARK: Window
  51. - (UIWindow *)window {
  52. UIWindow *result = nil;
  53. for (ApplicationDelegateService *service in services) {
  54. if (![service respondsToSelector:_cmd]) {
  55. continue;
  56. }
  57. UIWindow *value = [service window];
  58. if (value) {
  59. result = value;
  60. }
  61. }
  62. return result;
  63. }
  64. // MARK: Initializing
  65. - (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary<UIApplicationLaunchOptionsKey, id> *)launchOptions {
  66. BOOL result = NO;
  67. for (ApplicationDelegateService *service in services) {
  68. if (![service respondsToSelector:_cmd]) {
  69. continue;
  70. }
  71. if ([service application:application willFinishLaunchingWithOptions:launchOptions]) {
  72. result = YES;
  73. }
  74. }
  75. return result;
  76. }
  77. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary<UIApplicationLaunchOptionsKey, id> *)launchOptions {
  78. BOOL result = NO;
  79. for (ApplicationDelegateService *service in services) {
  80. if (![service respondsToSelector:_cmd]) {
  81. continue;
  82. }
  83. if ([service application:application didFinishLaunchingWithOptions:launchOptions]) {
  84. result = YES;
  85. }
  86. }
  87. return result;
  88. }
  89. /* Can be handled by Info.plist. Not yet supported by Godot.
  90. // MARK: Scene
  91. - (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options {}
  92. - (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet<UISceneSession *> *)sceneSessions {}
  93. */
  94. // MARK: Life-Cycle
  95. - (void)applicationDidBecomeActive:(UIApplication *)application {
  96. for (ApplicationDelegateService *service in services) {
  97. if (![service respondsToSelector:_cmd]) {
  98. continue;
  99. }
  100. [service applicationDidBecomeActive:application];
  101. }
  102. }
  103. - (void)applicationWillResignActive:(UIApplication *)application {
  104. for (ApplicationDelegateService *service in services) {
  105. if (![service respondsToSelector:_cmd]) {
  106. continue;
  107. }
  108. [service applicationWillResignActive:application];
  109. }
  110. }
  111. - (void)applicationDidEnterBackground:(UIApplication *)application {
  112. for (ApplicationDelegateService *service in services) {
  113. if (![service respondsToSelector:_cmd]) {
  114. continue;
  115. }
  116. [service applicationDidEnterBackground:application];
  117. }
  118. }
  119. - (void)applicationWillEnterForeground:(UIApplication *)application {
  120. for (ApplicationDelegateService *service in services) {
  121. if (![service respondsToSelector:_cmd]) {
  122. continue;
  123. }
  124. [service applicationWillEnterForeground:application];
  125. }
  126. }
  127. - (void)applicationWillTerminate:(UIApplication *)application {
  128. for (ApplicationDelegateService *service in services) {
  129. if (![service respondsToSelector:_cmd]) {
  130. continue;
  131. }
  132. [service applicationWillTerminate:application];
  133. }
  134. }
  135. // MARK: Environment Changes
  136. - (void)applicationProtectedDataDidBecomeAvailable:(UIApplication *)application {
  137. for (ApplicationDelegateService *service in services) {
  138. if (![service respondsToSelector:_cmd]) {
  139. continue;
  140. }
  141. [service applicationProtectedDataDidBecomeAvailable:application];
  142. }
  143. }
  144. - (void)applicationProtectedDataWillBecomeUnavailable:(UIApplication *)application {
  145. for (ApplicationDelegateService *service in services) {
  146. if (![service respondsToSelector:_cmd]) {
  147. continue;
  148. }
  149. [service applicationProtectedDataWillBecomeUnavailable:application];
  150. }
  151. }
  152. - (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
  153. for (ApplicationDelegateService *service in services) {
  154. if (![service respondsToSelector:_cmd]) {
  155. continue;
  156. }
  157. [service applicationDidReceiveMemoryWarning:application];
  158. }
  159. }
  160. - (void)applicationSignificantTimeChange:(UIApplication *)application {
  161. for (ApplicationDelegateService *service in services) {
  162. if (![service respondsToSelector:_cmd]) {
  163. continue;
  164. }
  165. [service applicationSignificantTimeChange:application];
  166. }
  167. }
  168. // MARK: App State Restoration
  169. - (BOOL)application:(UIApplication *)application shouldSaveSecureApplicationState:(NSCoder *)coder API_AVAILABLE(ios(13.2)) {
  170. BOOL result = NO;
  171. for (ApplicationDelegateService *service in services) {
  172. if (![service respondsToSelector:_cmd]) {
  173. continue;
  174. }
  175. if ([service application:application shouldSaveSecureApplicationState:coder]) {
  176. result = YES;
  177. }
  178. }
  179. return result;
  180. }
  181. - (BOOL)application:(UIApplication *)application shouldRestoreSecureApplicationState:(NSCoder *)coder API_AVAILABLE(ios(13.2)) {
  182. BOOL result = NO;
  183. for (ApplicationDelegateService *service in services) {
  184. if (![service respondsToSelector:_cmd]) {
  185. continue;
  186. }
  187. if ([service application:application shouldRestoreSecureApplicationState:coder]) {
  188. result = YES;
  189. }
  190. }
  191. return result;
  192. }
  193. - (UIViewController *)application:(UIApplication *)application viewControllerWithRestorationIdentifierPath:(NSArray<NSString *> *)identifierComponents coder:(NSCoder *)coder {
  194. for (ApplicationDelegateService *service in services) {
  195. if (![service respondsToSelector:_cmd]) {
  196. continue;
  197. }
  198. UIViewController *controller = [service application:application viewControllerWithRestorationIdentifierPath:identifierComponents coder:coder];
  199. if (controller) {
  200. return controller;
  201. }
  202. }
  203. return nil;
  204. }
  205. - (void)application:(UIApplication *)application willEncodeRestorableStateWithCoder:(NSCoder *)coder {
  206. for (ApplicationDelegateService *service in services) {
  207. if (![service respondsToSelector:_cmd]) {
  208. continue;
  209. }
  210. [service application:application willEncodeRestorableStateWithCoder:coder];
  211. }
  212. }
  213. - (void)application:(UIApplication *)application didDecodeRestorableStateWithCoder:(NSCoder *)coder {
  214. for (ApplicationDelegateService *service in services) {
  215. if (![service respondsToSelector:_cmd]) {
  216. continue;
  217. }
  218. [service application:application didDecodeRestorableStateWithCoder:coder];
  219. }
  220. }
  221. // MARK: Download Data in Background
  222. - (void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier completionHandler:(void (^)(void))completionHandler {
  223. for (ApplicationDelegateService *service in services) {
  224. if (![service respondsToSelector:_cmd]) {
  225. continue;
  226. }
  227. [service application:application handleEventsForBackgroundURLSession:identifier completionHandler:completionHandler];
  228. }
  229. completionHandler();
  230. }
  231. // MARK: Remote Notification
  232. // Moved to the iOS Plugin
  233. // MARK: User Activity and Handling Quick Actions
  234. - (BOOL)application:(UIApplication *)application willContinueUserActivityWithType:(NSString *)userActivityType {
  235. BOOL result = NO;
  236. for (ApplicationDelegateService *service in services) {
  237. if (![service respondsToSelector:_cmd]) {
  238. continue;
  239. }
  240. if ([service application:application willContinueUserActivityWithType:userActivityType]) {
  241. result = YES;
  242. }
  243. }
  244. return result;
  245. }
  246. - (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> *restorableObjects))restorationHandler {
  247. BOOL result = NO;
  248. for (ApplicationDelegateService *service in services) {
  249. if (![service respondsToSelector:_cmd]) {
  250. continue;
  251. }
  252. if ([service application:application continueUserActivity:userActivity restorationHandler:restorationHandler]) {
  253. result = YES;
  254. }
  255. }
  256. return result;
  257. }
  258. - (void)application:(UIApplication *)application didUpdateUserActivity:(NSUserActivity *)userActivity {
  259. for (ApplicationDelegateService *service in services) {
  260. if (![service respondsToSelector:_cmd]) {
  261. continue;
  262. }
  263. [service application:application didUpdateUserActivity:userActivity];
  264. }
  265. }
  266. - (void)application:(UIApplication *)application didFailToContinueUserActivityWithType:(NSString *)userActivityType error:(NSError *)error {
  267. for (ApplicationDelegateService *service in services) {
  268. if (![service respondsToSelector:_cmd]) {
  269. continue;
  270. }
  271. [service application:application didFailToContinueUserActivityWithType:userActivityType error:error];
  272. }
  273. }
  274. - (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL succeeded))completionHandler {
  275. for (ApplicationDelegateService *service in services) {
  276. if (![service respondsToSelector:_cmd]) {
  277. continue;
  278. }
  279. [service application:application performActionForShortcutItem:shortcutItem completionHandler:completionHandler];
  280. }
  281. }
  282. // MARK: WatchKit
  283. - (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void (^)(NSDictionary *replyInfo))reply {
  284. for (ApplicationDelegateService *service in services) {
  285. if (![service respondsToSelector:_cmd]) {
  286. continue;
  287. }
  288. [service application:application handleWatchKitExtensionRequest:userInfo reply:reply];
  289. }
  290. }
  291. // MARK: HealthKit
  292. - (void)applicationShouldRequestHealthAuthorization:(UIApplication *)application {
  293. for (ApplicationDelegateService *service in services) {
  294. if (![service respondsToSelector:_cmd]) {
  295. continue;
  296. }
  297. [service applicationShouldRequestHealthAuthorization:application];
  298. }
  299. }
  300. // MARK: Opening an URL
  301. - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options {
  302. for (ApplicationDelegateService *service in services) {
  303. if (![service respondsToSelector:_cmd]) {
  304. continue;
  305. }
  306. if ([service application:app openURL:url options:options]) {
  307. return YES;
  308. }
  309. }
  310. return NO;
  311. }
  312. // MARK: Disallowing Specified App Extension Types
  313. - (BOOL)application:(UIApplication *)application shouldAllowExtensionPointIdentifier:(UIApplicationExtensionPointIdentifier)extensionPointIdentifier {
  314. BOOL result = NO;
  315. for (ApplicationDelegateService *service in services) {
  316. if (![service respondsToSelector:_cmd]) {
  317. continue;
  318. }
  319. if ([service application:application shouldAllowExtensionPointIdentifier:extensionPointIdentifier]) {
  320. result = YES;
  321. }
  322. }
  323. return result;
  324. }
  325. // MARK: SiriKit
  326. - (id)application:(UIApplication *)application handlerForIntent:(INIntent *)intent API_AVAILABLE(ios(14.0)) {
  327. for (ApplicationDelegateService *service in services) {
  328. if (![service respondsToSelector:_cmd]) {
  329. continue;
  330. }
  331. id result = [service application:application handlerForIntent:intent];
  332. if (result) {
  333. return result;
  334. }
  335. }
  336. return nil;
  337. }
  338. // MARK: CloudKit
  339. - (void)application:(UIApplication *)application userDidAcceptCloudKitShareWithMetadata:(CKShareMetadata *)cloudKitShareMetadata {
  340. for (ApplicationDelegateService *service in services) {
  341. if (![service respondsToSelector:_cmd]) {
  342. continue;
  343. }
  344. [service application:application userDidAcceptCloudKitShareWithMetadata:cloudKitShareMetadata];
  345. }
  346. }
  347. /* Handled By Info.plist file for now
  348. // MARK: Interface Geometry
  349. - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {}
  350. */
  351. @end