@@ -2,6 +2,7 @@
2#import "ViewController.h"
2#import "ViewController.h"
3#import <UserNotifications/UserNotifications.h>
3#import <UserNotifications/UserNotifications.h>
5+extern void handlerIO(HsStablePtr);
5extern void handlerCString(const char * _Nonnull, HsStablePtr);
6extern void handlerCString(const char * _Nonnull, HsStablePtr);
7@interface AppDelegate ()
8@interface AppDelegate ()
@@ -9,6 +10,14 @@ extern void handlerCString(const char * _Nonnull, HsStablePtr);
11HsStablePtr globalHandler = 0;
12HsStablePtr 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;
12BOOL global_requestAuthorizationWithOptions = NO;
21BOOL global_requestAuthorizationWithOptions = NO;
13BOOL global_requestAuthorizationOptionBadge = NO;
22BOOL global_requestAuthorizationOptionBadge = NO;
14BOOL global_requestAuthorizationOptionSound = NO;
23BOOL global_requestAuthorizationOptionSound = NO;
@@ -20,7 +29,14 @@ HsStablePtr global_didFailToRegisterForRemoteNotificationsWithError = 0;
21@implementation AppDelegate
30@implementation AppDelegate
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);
23- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
38- (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.
24 self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
40 self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
25 // Override point for customization after application launch.
41 // Override point for customization after application launch.
26 self.window.rootViewController = [[ViewController alloc] initWithHandler:globalHandler];
42 self.window.rootViewController = [[ViewController alloc] initWithHandler:globalHandler];
@@ -49,49 +65,70 @@ HsStablePtr global_didFailToRegisterForRemoteNotificationsWithError = 0;
49 if (global_registerForRemoteNotifications) {
65 if (global_registerForRemoteNotifications) {
50 [application registerForRemoteNotifications];
66 [application registerForRemoteNotifications];
68+ handlerIO(global_didFinishLaunchingWithOptions);
52 return YES;
69 return YES;
55- (void)applicationWillResignActive:(UIApplication *)application {
72- (void)applicationWillResignActive:(UIApplication *)application {
56 // 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.
73 // 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.
57 // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
74 // 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);
61- (void)applicationDidEnterBackground:(UIApplication *)application {
79- (void)applicationDidEnterBackground:(UIApplication *)application {
62 // 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.
80 // 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.
63 // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
81 // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
82+ handlerIO(global_applicationDidEnterBackground);
67- (void)applicationWillEnterForeground:(UIApplication *)application {
86- (void)applicationWillEnterForeground:(UIApplication *)application {
68 // 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.
87 // 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);
72- (void)applicationDidBecomeActive:(UIApplication *)application {
92- (void)applicationDidBecomeActive:(UIApplication *)application {
73 // 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.
93 // 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);
77- (void)applicationWillTerminate:(UIApplication *)application {
98- (void)applicationWillTerminate:(UIApplication *)application {
78 // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
99 // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
100+ handlerIO(global_applicationWillTerminate);
81- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
103- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
104+ // Tells the delegate that the app successfully registered with Apple Push Notification service (APNs).
82 NSString *deviceTokenString = [deviceToken base64EncodedStringWithOptions: 0];
105 NSString *deviceTokenString = [deviceToken base64EncodedStringWithOptions: 0];
83 handlerCString([deviceTokenString UTF8String], global_didRegisterForRemoteNotificationsWithDeviceToken);
106 handlerCString([deviceTokenString UTF8String], global_didRegisterForRemoteNotificationsWithDeviceToken);
86- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
109- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
110+ // Sent to the delegate when Apple Push Notification service cannot successfully complete the registration process.
87− NSString *errorString = [error localizedDescription];
111+ NSString *errorString = [error localizedDescription];
88− handlerCString([errorString UTF8String], global_didFailToRegisterForRemoteNotificationsWithError);
112+ handlerCString([errorString UTF8String], global_didFailToRegisterForRemoteNotificationsWithError);
115+- (void)applicationSignificantTimeChange:(UIApplication *)application {
116+ // Tells the delegate when there is a significant change in the time.
117+ handlerIO(global_applicationSignificantTimeChange);
93void runInWKWebView(HsStablePtr handler,
122void runInWKWebView(HsStablePtr handler,
94 const char * _Nonnull progName,
123 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,
95 const BOOL hs_requestAuthorizationWithOptions,
132 const BOOL hs_requestAuthorizationWithOptions,
96 const BOOL hs_requestAuthorizationOptionBadge,
133 const BOOL hs_requestAuthorizationOptionBadge,
97 const BOOL hs_requestAuthorizationOptionSound,
134 const BOOL hs_requestAuthorizationOptionSound,
@@ -102,6 +139,14 @@ void runInWKWebView(HsStablePtr handler,
102 HsStablePtr hs_didFailToRegisterForRemoteNotificationsWithError) {
139 HsStablePtr hs_didFailToRegisterForRemoteNotificationsWithError) {
103 @autoreleasepool {
140 @autoreleasepool {
104 globalHandler = handler;
141 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;
105 global_requestAuthorizationWithOptions = hs_requestAuthorizationWithOptions;
150 global_requestAuthorizationWithOptions = hs_requestAuthorizationWithOptions;
106 global_requestAuthorizationOptionBadge = hs_requestAuthorizationOptionBadge;
151 global_requestAuthorizationOptionBadge = hs_requestAuthorizationOptionBadge;
107 global_requestAuthorizationOptionSound = hs_requestAuthorizationOptionSound;
152 global_requestAuthorizationOptionSound = hs_requestAuthorizationOptionSound;