@@ -1,9 +1,10 @@
11#import "AppDelegate.h"
22#import "ViewController.h"
33#import <UserNotifications/UserNotifications.h>
4+#import <stdint.h>
45
5−extern void handlerIO(HsStablePtr);
6−extern void handlerCString(const char * _Nonnull, HsStablePtr);
6+extern void callIO(HsStablePtr);
7+extern void callWithCString(const char * _Nonnull, HsStablePtr);
78
89@interface AppDelegate ()
910
@@ -18,12 +19,12 @@ HsStablePtr global_applicationDidEnterBackground = 0;
1819HsStablePtr global_applicationWillEnterForeground = 0;
1920HsStablePtr global_applicationWillTerminate = 0;
2021HsStablePtr global_applicationSignificantTimeChange = 0;
21−BOOL global_requestAuthorizationWithOptions = NO;
22−BOOL global_requestAuthorizationOptionBadge = NO;
23−BOOL global_requestAuthorizationOptionSound = NO;
24−BOOL global_requestAuthorizationOptionAlert = NO;
25−BOOL global_requestAuthorizationOptionCarPlay = NO;
26−BOOL global_registerForRemoteNotifications = NO;
22+uint64_t global_requestAuthorizationWithOptions = 0;
23+uint64_t global_requestAuthorizationOptionBadge = 0;
24+uint64_t global_requestAuthorizationOptionSound = 0;
25+uint64_t global_requestAuthorizationOptionAlert = 0;
26+uint64_t global_requestAuthorizationOptionCarPlay = 0;
27+uint64_t global_registerForRemoteNotifications = 0;
2728HsStablePtr global_didRegisterForRemoteNotificationsWithDeviceToken = 0;
2829HsStablePtr global_didFailToRegisterForRemoteNotificationsWithError = 0;
2930
@@ -31,7 +32,7 @@ HsStablePtr global_didFailToRegisterForRemoteNotificationsWithError = 0;
3132
3233- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
3334 // 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);
3536 return YES;
3637}
3738
@@ -43,78 +44,79 @@ HsStablePtr global_didFailToRegisterForRemoteNotificationsWithError = 0;
4344 self.window.backgroundColor = [UIColor whiteColor];
4445 [self.window makeKeyAndVisible];
4546 UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
47+ center.delegate = self;
4648 if (global_requestAuthorizationWithOptions) {
4749 UNAuthorizationOptions options = (UNAuthorizationOptions)0;
4850 if (global_requestAuthorizationOptionBadge) {
49− options = options + UNAuthorizationOptionBadge;
51+ options = options | UNAuthorizationOptionBadge;
5052 }
5153 if (global_requestAuthorizationOptionSound) {
52− options = options + UNAuthorizationOptionSound;
54+ options = options | UNAuthorizationOptionSound;
5355 }
5456 if (global_requestAuthorizationOptionAlert) {
55− options = options + UNAuthorizationOptionAlert;
57+ options = options | UNAuthorizationOptionAlert;
5658 }
5759 if (global_requestAuthorizationOptionCarPlay) {
58− options = options + UNAuthorizationOptionCarPlay;
60+ options = options | UNAuthorizationOptionCarPlay;
5961 }
6062 [center requestAuthorizationWithOptions:(options)
6163 completionHandler:^(BOOL granted, NSError * _Nullable error) {
6264 // Handler used to alter application behavior based on types of notifications authorized
6365 }];
66+ if (global_registerForRemoteNotifications) {
67+ [application registerForRemoteNotifications];
68+ }
6469 }
65− if (global_registerForRemoteNotifications) {
66− [application registerForRemoteNotifications];
67− }
68− handlerIO(global_didFinishLaunchingWithOptions);
70+ callIO(global_didFinishLaunchingWithOptions);
6971 return YES;
7072}
7173
7274- (void)applicationWillResignActive:(UIApplication *)application {
7375 // 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.
7476 // 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);
7678}
7779
7880
7981- (void)applicationDidEnterBackground:(UIApplication *)application {
8082 // 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.
8183 // 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);
8385}
8486
8587
8688- (void)applicationWillEnterForeground:(UIApplication *)application {
8789 // 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);
8991}
9092
9193
9294- (void)applicationDidBecomeActive:(UIApplication *)application {
9395 // 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);
9597}
9698
9799
98100- (void)applicationWillTerminate:(UIApplication *)application {
99101 // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
100− handlerIO(global_applicationWillTerminate);
102+ callIO(global_applicationWillTerminate);
101103}
102104
103105- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
104106 // Tells the delegate that the app successfully registered with Apple Push Notification service (APNs).
105107 NSString *deviceTokenString = [deviceToken base64EncodedStringWithOptions: 0];
106− handlerCString([deviceTokenString UTF8String], global_didRegisterForRemoteNotificationsWithDeviceToken);
108+ callWithCString([deviceTokenString UTF8String], global_didRegisterForRemoteNotificationsWithDeviceToken);
107109}
108110
109111- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
110112 // Sent to the delegate when Apple Push Notification service cannot successfully complete the registration process.
111113 NSString *errorString = [error localizedDescription];
112− handlerCString([errorString UTF8String], global_didFailToRegisterForRemoteNotificationsWithError);
114+ callWithCString([errorString UTF8String], global_didFailToRegisterForRemoteNotificationsWithError);
113115}
114116
115117- (void)applicationSignificantTimeChange:(UIApplication *)application {
116118 // Tells the delegate when there is a significant change in the time.
117− handlerIO(global_applicationSignificantTimeChange);
119+ callIO(global_applicationSignificantTimeChange);
118120}
119121
120122@end
@@ -129,12 +131,12 @@ void runInWKWebView(HsStablePtr handler,
129131 HsStablePtr hs_applicationWillEnterForeground,
130132 HsStablePtr hs_applicationWillTerminate,
131133 HsStablePtr hs_applicationSignificantTimeChange,
132− const BOOL hs_requestAuthorizationWithOptions,
133− const BOOL hs_requestAuthorizationOptionBadge,
134− const BOOL hs_requestAuthorizationOptionSound,
135− const BOOL hs_requestAuthorizationOptionAlert,
136− const BOOL hs_requestAuthorizationOptionCarPlay,
137− const BOOL hs_registerForRemoteNotifications,
134+ const uint64_t hs_requestAuthorizationWithOptions,
135+ const uint64_t hs_requestAuthorizationOptionBadge,
136+ const uint64_t hs_requestAuthorizationOptionSound,
137+ const uint64_t hs_requestAuthorizationOptionAlert,
138+ const uint64_t hs_requestAuthorizationOptionCarPlay,
139+ const uint64_t hs_registerForRemoteNotifications,
138140 HsStablePtr hs_didRegisterForRemoteNotificationsWithDeviceToken,
139141 HsStablePtr hs_didFailToRegisterForRemoteNotificationsWithError) {
140142 @autoreleasepool {