@@ -1,9 +1,10 @@
1#import "AppDelegate.h"
1#import "AppDelegate.h"
2#import "ViewController.h"
2#import "ViewController.h"
3#import <UserNotifications/UserNotifications.h>
3#import <UserNotifications/UserNotifications.h>
5−extern void handlerIO(HsStablePtr);
6+extern void callIO(HsStablePtr);
6−extern void handlerCString(const char * _Nonnull, HsStablePtr);
7+extern void callWithCString(const char * _Nonnull, HsStablePtr);
8@interface AppDelegate ()
9@interface AppDelegate ()
@@ -18,12 +19,12 @@ HsStablePtr global_applicationDidEnterBackground = 0;
18HsStablePtr global_applicationWillEnterForeground = 0;
19HsStablePtr global_applicationWillEnterForeground = 0;
19HsStablePtr global_applicationWillTerminate = 0;
20HsStablePtr global_applicationWillTerminate = 0;
20HsStablePtr global_applicationSignificantTimeChange = 0;
21HsStablePtr global_applicationSignificantTimeChange = 0;
21−BOOL global_requestAuthorizationWithOptions = NO;
22+uint64_t global_requestAuthorizationWithOptions = 0;
22−BOOL global_requestAuthorizationOptionBadge = NO;
23+uint64_t global_requestAuthorizationOptionBadge = 0;
23−BOOL global_requestAuthorizationOptionSound = NO;
24+uint64_t global_requestAuthorizationOptionSound = 0;
24−BOOL global_requestAuthorizationOptionAlert = NO;
25+uint64_t global_requestAuthorizationOptionAlert = 0;
25−BOOL global_requestAuthorizationOptionCarPlay = NO;
26+uint64_t global_requestAuthorizationOptionCarPlay = 0;
26−BOOL global_registerForRemoteNotifications = NO;
27+uint64_t global_registerForRemoteNotifications = 0;
27HsStablePtr global_didRegisterForRemoteNotificationsWithDeviceToken = 0;
28HsStablePtr global_didRegisterForRemoteNotificationsWithDeviceToken = 0;
28HsStablePtr global_didFailToRegisterForRemoteNotificationsWithError = 0;
29HsStablePtr global_didFailToRegisterForRemoteNotificationsWithError = 0;
@@ -31,7 +32,7 @@ HsStablePtr global_didFailToRegisterForRemoteNotificationsWithError = 0;
32- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
33- (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 // Tells the delegate that the launch process has begun but that state restoration has not yet occurred.
34− handlerIO(global_willFinishLaunchingWithOptions);
35+ callIO(global_willFinishLaunchingWithOptions);
35 return YES;
36 return YES;
@@ -43,78 +44,79 @@ HsStablePtr global_didFailToRegisterForRemoteNotificationsWithError = 0;
43 self.window.backgroundColor = [UIColor whiteColor];
44 self.window.backgroundColor = [UIColor whiteColor];
44 [self.window makeKeyAndVisible];
45 [self.window makeKeyAndVisible];
45 UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
46 UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
47+ center.delegate = self;
46 if (global_requestAuthorizationWithOptions) {
48 if (global_requestAuthorizationWithOptions) {
47 UNAuthorizationOptions options = (UNAuthorizationOptions)0;
49 UNAuthorizationOptions options = (UNAuthorizationOptions)0;
48 if (global_requestAuthorizationOptionBadge) {
50 if (global_requestAuthorizationOptionBadge) {
49− options = options + UNAuthorizationOptionBadge;
51+ options = options | UNAuthorizationOptionBadge;
51 if (global_requestAuthorizationOptionSound) {
53 if (global_requestAuthorizationOptionSound) {
52− options = options + UNAuthorizationOptionSound;
54+ options = options | UNAuthorizationOptionSound;
54 if (global_requestAuthorizationOptionAlert) {
56 if (global_requestAuthorizationOptionAlert) {
55− options = options + UNAuthorizationOptionAlert;
57+ options = options | UNAuthorizationOptionAlert;
57 if (global_requestAuthorizationOptionCarPlay) {
59 if (global_requestAuthorizationOptionCarPlay) {
58− options = options + UNAuthorizationOptionCarPlay;
60+ options = options | UNAuthorizationOptionCarPlay;
60 [center requestAuthorizationWithOptions:(options)
62 [center requestAuthorizationWithOptions:(options)
61 completionHandler:^(BOOL granted, NSError * _Nullable error) {
63 completionHandler:^(BOOL granted, NSError * _Nullable error) {
62 // Handler used to alter application behavior based on types of notifications authorized
64 // Handler used to alter application behavior based on types of notifications authorized
66+ if (global_registerForRemoteNotifications) {
67+ [application registerForRemoteNotifications];
65− if (global_registerForRemoteNotifications) {
66− [application registerForRemoteNotifications];
68− handlerIO(global_didFinishLaunchingWithOptions);
70+ callIO(global_didFinishLaunchingWithOptions);
69 return YES;
71 return YES;
72- (void)applicationWillResignActive:(UIApplication *)application {
74- (void)applicationWillResignActive:(UIApplication *)application {
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.
75 // 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.
74 // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
76 // 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);
77+ callIO(global_applicationWillResignActive);
79- (void)applicationDidEnterBackground:(UIApplication *)application {
81- (void)applicationDidEnterBackground:(UIApplication *)application {
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.
82 // 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.
81 // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
83 // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
82− handlerIO(global_applicationDidEnterBackground);
84+ callIO(global_applicationDidEnterBackground);
86- (void)applicationWillEnterForeground:(UIApplication *)application {
88- (void)applicationWillEnterForeground:(UIApplication *)application {
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.
89 // 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);
90+ callIO(global_applicationWillEnterForeground);
92- (void)applicationDidBecomeActive:(UIApplication *)application {
94- (void)applicationDidBecomeActive:(UIApplication *)application {
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.
95 // 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);
96+ callIO(global_applicationDidBecomeActive);
98- (void)applicationWillTerminate:(UIApplication *)application {
100- (void)applicationWillTerminate:(UIApplication *)application {
99 // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
101 // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
100− handlerIO(global_applicationWillTerminate);
102+ callIO(global_applicationWillTerminate);
103- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
105- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
104 // Tells the delegate that the app successfully registered with Apple Push Notification service (APNs).
106 // Tells the delegate that the app successfully registered with Apple Push Notification service (APNs).
105 NSString *deviceTokenString = [deviceToken base64EncodedStringWithOptions: 0];
107 NSString *deviceTokenString = [deviceToken base64EncodedStringWithOptions: 0];
106− handlerCString([deviceTokenString UTF8String], global_didRegisterForRemoteNotificationsWithDeviceToken);
108+ callWithCString([deviceTokenString UTF8String], global_didRegisterForRemoteNotificationsWithDeviceToken);
109- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
111- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
110 // Sent to the delegate when Apple Push Notification service cannot successfully complete the registration process.
112 // Sent to the delegate when Apple Push Notification service cannot successfully complete the registration process.
111 NSString *errorString = [error localizedDescription];
113 NSString *errorString = [error localizedDescription];
112− handlerCString([errorString UTF8String], global_didFailToRegisterForRemoteNotificationsWithError);
114+ callWithCString([errorString UTF8String], global_didFailToRegisterForRemoteNotificationsWithError);
115- (void)applicationSignificantTimeChange:(UIApplication *)application {
117- (void)applicationSignificantTimeChange:(UIApplication *)application {
116 // Tells the delegate when there is a significant change in the time.
118 // Tells the delegate when there is a significant change in the time.
117− handlerIO(global_applicationSignificantTimeChange);
119+ callIO(global_applicationSignificantTimeChange);
@@ -129,12 +131,12 @@ void runInWKWebView(HsStablePtr handler,
129 HsStablePtr hs_applicationWillEnterForeground,
131 HsStablePtr hs_applicationWillEnterForeground,
130 HsStablePtr hs_applicationWillTerminate,
132 HsStablePtr hs_applicationWillTerminate,
131 HsStablePtr hs_applicationSignificantTimeChange,
133 HsStablePtr hs_applicationSignificantTimeChange,
132− const BOOL hs_requestAuthorizationWithOptions,
134+ const uint64_t hs_requestAuthorizationWithOptions,
133− const BOOL hs_requestAuthorizationOptionBadge,
135+ const uint64_t hs_requestAuthorizationOptionBadge,
134− const BOOL hs_requestAuthorizationOptionSound,
136+ const uint64_t hs_requestAuthorizationOptionSound,
135− const BOOL hs_requestAuthorizationOptionAlert,
137+ const uint64_t hs_requestAuthorizationOptionAlert,
136− const BOOL hs_requestAuthorizationOptionCarPlay,
138+ const uint64_t hs_requestAuthorizationOptionCarPlay,
137− const BOOL hs_registerForRemoteNotifications,
139+ const uint64_t hs_registerForRemoteNotifications,
138 HsStablePtr hs_didRegisterForRemoteNotificationsWithDeviceToken,
140 HsStablePtr hs_didRegisterForRemoteNotificationsWithDeviceToken,
139 HsStablePtr hs_didFailToRegisterForRemoteNotificationsWithError) {
141 HsStablePtr hs_didFailToRegisterForRemoteNotificationsWithError) {
140 @autoreleasepool {
142 @autoreleasepool {