@@ -2,6 +2,7 @@
22#import "ViewController.h"
33#import <UserNotifications/UserNotifications.h>
44
5+extern void handlerIO(HsStablePtr);
56extern void handlerCString(const char * _Nonnull, HsStablePtr);
67
78@interface AppDelegate ()
@@ -9,6 +10,14 @@ extern void handlerCString(const char * _Nonnull, HsStablePtr);
910@end
1011
1112HsStablePtr globalHandler = 0;
13+HsStablePtr global_willFinishLaunchingWithOptions = 0;
14+HsStablePtr global_didFinishLaunchingWithOptions = 0;
15+HsStablePtr global_applicationDidBecomeActive = 0;
16+HsStablePtr global_applicationWillResignActive = 0;
17+HsStablePtr global_applicationDidEnterBackground = 0;
18+HsStablePtr global_applicationWillEnterForeground = 0;
19+HsStablePtr global_applicationWillTerminate = 0;
20+HsStablePtr global_applicationSignificantTimeChange = 0;
1221BOOL global_requestAuthorizationWithOptions = NO;
1322BOOL global_requestAuthorizationOptionBadge = NO;
1423BOOL global_requestAuthorizationOptionSound = NO;
@@ -20,7 +29,14 @@ HsStablePtr global_didFailToRegisterForRemoteNotificationsWithError = 0;
2029
2130@implementation AppDelegate
2231
32+- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
33+ // Tells the delegate that the launch process has begun but that state restoration has not yet occurred.
34+ handlerIO(global_willFinishLaunchingWithOptions);
35+ return YES;
36+}
37+
2338- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
39+ // Tells the delegate that the launch process is almost done and the app is almost ready to run.
2440 self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
2541 // Override point for customization after application launch.
2642 self.window.rootViewController = [[ViewController alloc] initWithHandler:globalHandler];
@@ -49,49 +65,70 @@ HsStablePtr global_didFailToRegisterForRemoteNotificationsWithError = 0;
4965 if (global_registerForRemoteNotifications) {
5066 [application registerForRemoteNotifications];
5167 }
68+ handlerIO(global_didFinishLaunchingWithOptions);
5269 return YES;
5370}
5471
5572- (void)applicationWillResignActive:(UIApplication *)application {
5673 // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
5774 // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
75+ handlerIO(global_applicationWillResignActive);
5876}
5977
6078
6179- (void)applicationDidEnterBackground:(UIApplication *)application {
6280 // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
6381 // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
82+ handlerIO(global_applicationDidEnterBackground);
6483}
6584
6685
6786- (void)applicationWillEnterForeground:(UIApplication *)application {
6887 // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
88+ handlerIO(global_applicationWillEnterForeground);
6989}
7090
7191
7292- (void)applicationDidBecomeActive:(UIApplication *)application {
7393 // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
94+ handlerIO(global_applicationDidBecomeActive);
7495}
7596
7697
7798- (void)applicationWillTerminate:(UIApplication *)application {
7899 // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
100+ handlerIO(global_applicationWillTerminate);
79101}
80102
81103- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
104+ // Tells the delegate that the app successfully registered with Apple Push Notification service (APNs).
82105 NSString *deviceTokenString = [deviceToken base64EncodedStringWithOptions: 0];
83106 handlerCString([deviceTokenString UTF8String], global_didRegisterForRemoteNotificationsWithDeviceToken);
84107}
85108
86109- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
87− NSString *errorString = [error localizedDescription];
88− handlerCString([errorString UTF8String], global_didFailToRegisterForRemoteNotificationsWithError);
110+ // Sent to the delegate when Apple Push Notification service cannot successfully complete the registration process.
111+ NSString *errorString = [error localizedDescription];
112+ handlerCString([errorString UTF8String], global_didFailToRegisterForRemoteNotificationsWithError);
113+}
114+
115+- (void)applicationSignificantTimeChange:(UIApplication *)application {
116+ // Tells the delegate when there is a significant change in the time.
117+ handlerIO(global_applicationSignificantTimeChange);
89118}
90119
91120@end
92121
93122void runInWKWebView(HsStablePtr handler,
94123 const char * _Nonnull progName,
124+ HsStablePtr hs_willFinishLaunchingWithOptions,
125+ HsStablePtr hs_didFinishLaunchingWithOptions,
126+ HsStablePtr hs_applicationDidBecomeActive,
127+ HsStablePtr hs_applicationWillResignActive,
128+ HsStablePtr hs_applicationDidEnterBackground,
129+ HsStablePtr hs_applicationWillEnterForeground,
130+ HsStablePtr hs_applicationWillTerminate,
131+ HsStablePtr hs_applicationSignificantTimeChange,
95132 const BOOL hs_requestAuthorizationWithOptions,
96133 const BOOL hs_requestAuthorizationOptionBadge,
97134 const BOOL hs_requestAuthorizationOptionSound,
@@ -102,6 +139,14 @@ void runInWKWebView(HsStablePtr handler,
102139 HsStablePtr hs_didFailToRegisterForRemoteNotificationsWithError) {
103140 @autoreleasepool {
104141 globalHandler = handler;
142+ global_willFinishLaunchingWithOptions = hs_willFinishLaunchingWithOptions;
143+ global_didFinishLaunchingWithOptions = hs_didFinishLaunchingWithOptions;
144+ global_applicationDidBecomeActive = hs_applicationDidBecomeActive;
145+ global_applicationWillResignActive = hs_applicationWillResignActive;
146+ global_applicationDidEnterBackground = hs_applicationDidEnterBackground;
147+ global_applicationWillEnterForeground = hs_applicationWillEnterForeground;
148+ global_applicationWillTerminate = hs_applicationWillTerminate;
149+ global_applicationSignificantTimeChange = hs_applicationSignificantTimeChange;
105150 global_requestAuthorizationWithOptions = hs_requestAuthorizationWithOptions;
106151 global_requestAuthorizationOptionBadge = hs_requestAuthorizationOptionBadge;
107152 global_requestAuthorizationOptionSound = hs_requestAuthorizationOptionSound;