@@ -1,12 +1,15 @@
11#import "AppDelegate.h"
22#import "ViewController.h"
3+#import <UserNotifications/UserNotifications.h>
34
4−@interface AppDelegate ()
5+extern void didRegisterForRemoteNotificationsWithDeviceTokenCallback(HsStablePtr, const char * _Nonnull);
56
7+@interface AppDelegate ()
68
79@end
810
911HsStablePtr globalHandler = 0;
12+HsStablePtr globalDeviceTokenHook = 0;
1013
1114@implementation AppDelegate
1215
@@ -16,6 +19,13 @@ HsStablePtr globalHandler = 0;
1619 self.window.rootViewController = [[ViewController alloc] initWithHandler:globalHandler];
1720 self.window.backgroundColor = [UIColor whiteColor];
1821 [self.window makeKeyAndVisible];
22+ UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
23+ [center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert + UNAuthorizationOptionSound + UNAuthorizationOptionBadge)
24+ completionHandler:^(BOOL granted, NSError * _Nullable error) {
25+ // Handler used to alter application behavior based on types of notifications authorized
26+ // Perhaps we don't need to do anything here.
27+ }];
28+ [application registerForRemoteNotifications];
1929 return YES;
2030}
2131
@@ -45,11 +55,17 @@ HsStablePtr globalHandler = 0;
4555 // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
4656}
4757
58+- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
59+ NSString *deviceTokenString = [deviceToken base64EncodedStringWithOptions: 0];
60+ didRegisterForRemoteNotificationsWithDeviceTokenCallback(globalDeviceTokenHook, [deviceTokenString UTF8String]);
61+}
62+
4863@end
4964
50−void runInWKWebView(HsStablePtr handler, const char * _Nonnull progName) {
65+void runInWKWebView(HsStablePtr handler, const char * _Nonnull progName, HsStablePtr deviceTokenHook) {
5166 @autoreleasepool {
5267 globalHandler = handler;
68+ globalDeviceTokenHook = deviceTokenHook;
5369 const char * _Nonnull argv [] = {"", 0};
5470 UIApplicationMain(0, argv, nil, NSStringFromClass([AppDelegate class]));
5571 }