on master help sign in
Add requestAuthorizationWithOptions flag
837417cAli Abrar
jsaddle-wkwebview/cbits-uikit/AppDelegate.m+12−7
@@ -9,8 +9,9 @@ extern void handlerCString(const char * _Nonnull, HsStablePtr);
9@end
9@end
10
10
11HsStablePtr globalHandler = 0;
11HsStablePtr globalHandler = 0;
12−HsStablePtr global_didRegisterForRemoteNotificationsWithDeviceToken = 0;
12+BOOL global_requestAuthorizationWithOptions = NO;
13BOOL global_registerForRemoteNotifications = NO;
13BOOL global_registerForRemoteNotifications = NO;
14+HsStablePtr global_didRegisterForRemoteNotificationsWithDeviceToken = 0;
14
15
15@implementation AppDelegate
16@implementation AppDelegate
16
17
@@ -21,11 +22,13 @@ BOOL global_registerForRemoteNotifications = NO;
21 self.window.backgroundColor = [UIColor whiteColor];
22 self.window.backgroundColor = [UIColor whiteColor];
22 [self.window makeKeyAndVisible];
23 [self.window makeKeyAndVisible];
23 UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
24 UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
25+ if (global_requestAuthorizationWithOptions) {
24− [center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert + UNAuthorizationOptionSound + UNAuthorizationOptionBadge)
26+ [center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert + UNAuthorizationOptionSound + UNAuthorizationOptionBadge)
25− completionHandler:^(BOOL granted, NSError * _Nullable error) {
27+ completionHandler:^(BOOL granted, NSError * _Nullable error) {
26− // Handler used to alter application behavior based on types of notifications authorized
28+ // Handler used to alter application behavior based on types of notifications authorized
27− // Perhaps we don't need to do anything here.
29+ // Perhaps we don't need to do anything here.
28− }];
30+ }];
31+ }
29 if (global_registerForRemoteNotifications) {
32 if (global_registerForRemoteNotifications) {
30 [application registerForRemoteNotifications];
33 [application registerForRemoteNotifications];
31 }
34 }
@@ -71,12 +74,14 @@ BOOL global_registerForRemoteNotifications = NO;
71
74
72void runInWKWebView(HsStablePtr handler,
75void runInWKWebView(HsStablePtr handler,
73 const char * _Nonnull progName,
76 const char * _Nonnull progName,
77+ const BOOL hs_requestAuthorizationWithOptions,
74 const BOOL hs_registerForRemoteNotifications,
78 const BOOL hs_registerForRemoteNotifications,
75 HsStablePtr hs_didRegisterForRemoteNotificationsWithDeviceToken) {
79 HsStablePtr hs_didRegisterForRemoteNotificationsWithDeviceToken) {
76 @autoreleasepool {
80 @autoreleasepool {
77 globalHandler = handler;
81 globalHandler = handler;
78− global_didRegisterForRemoteNotificationsWithDeviceToken = hs_didRegisterForRemoteNotificationsWithDeviceToken;
82+ global_requestAuthorizationWithOptions = hs_requestAuthorizationWithOptions;
79 global_registerForRemoteNotifications = hs_registerForRemoteNotifications;
83 global_registerForRemoteNotifications = hs_registerForRemoteNotifications;
84+ global_didRegisterForRemoteNotificationsWithDeviceToken = hs_didRegisterForRemoteNotificationsWithDeviceToken;
80 const char * _Nonnull argv [] = {"", 0};
85 const char * _Nonnull argv [] = {"", 0};
81 UIApplicationMain(0, argv, nil, NSStringFromClass([AppDelegate class]));
86 UIApplicationMain(0, argv, nil, NSStringFromClass([AppDelegate class]));
82 }
87 }
jsaddle-wkwebview/src-ghc/Language/Javascript/JSaddle/WKWebView.hs+12−5
@@ -15,7 +15,12 @@ import Foreign.C.Types
15import Foreign.StablePtr (StablePtr, newStablePtr)
15import Foreign.StablePtr (StablePtr, newStablePtr)
16import Language.Javascript.JSaddle (JSM)
16import Language.Javascript.JSaddle (JSM)
17
17
18−foreign import ccall runInWKWebView :: StablePtr (WKWebView -> IO ()) -> CString -> CChar -> StablePtr (CString -> IO ()) -> IO ()
18+foreign import ccall runInWKWebView :: StablePtr (WKWebView -> IO ())
19+ -> CString
20+ -> CChar -- requestAuthorizationWithOptions
21+ -> CChar -- registerForRemoteNotifications
22+ -> StablePtr (CString -> IO ()) -- didRegisterForRemoteNotificationsWithDeviceToken
23+ -> IO ()
19
24
20-- | Run JSaddle in a WKWebView
25-- | Run JSaddle in a WKWebView
21run :: (CString -> IO ()) -> JSM () -> IO ()
26run :: (CString -> IO ()) -> JSM () -> IO ()
@@ -23,7 +28,7 @@ run didRegisterForRemoteNotificationsWithDeviceToken f = do
23 handler <- newStablePtr (jsaddleMain f)
28 handler <- newStablePtr (jsaddleMain f)
24 progName <- getProgName
29 progName <- getProgName
25 deviceTokenHandler <- newStablePtr didRegisterForRemoteNotificationsWithDeviceToken
30 deviceTokenHandler <- newStablePtr didRegisterForRemoteNotificationsWithDeviceToken
26− withCString progName $ \pn -> runInWKWebView handler pn 1 deviceTokenHandler
31+ withCString progName $ \pn -> runInWKWebView handler pn 1 1 deviceTokenHandler
27
32
28-- | Run JSaddle in a WKWebView first loading the specified file
33-- | Run JSaddle in a WKWebView first loading the specified file
29-- from the mainBundle (relative to the resourcePath).
34-- from the mainBundle (relative to the resourcePath).
@@ -35,11 +40,13 @@ runFile :: ByteString -- ^ The file to navigate to.
35runFile url allowing cfg f = do
40runFile url allowing cfg f = do
36 handler <- newStablePtr (jsaddleMainFile url allowing f)
41 handler <- newStablePtr (jsaddleMainFile url allowing f)
37 progName <- getProgName
42 progName <- getProgName
43+ let requestAuthorizationWithOptions = boolToCChar $ _appDelegateConfig_requestAuthorizationWithOptions cfg
44+ registerForRemoteNotifications = boolToCChar $ _appDelegateConfig_registerForRemoteNotifications cfg
38− deviceTokenHandler <- newStablePtr $ _appDelegateConfig_didRegisterForRemoteNotificationsWithDeviceToken cfg
45+ didRegisterForRemoteNotificationsWithDeviceToken <- newStablePtr $ _appDelegateConfig_didRegisterForRemoteNotificationsWithDeviceToken cfg
39− let registerForRemoteNotifications = boolToCChar $ _appDelegateConfig_registerForRemoteNotifications cfg
40 withCString progName $ \pn -> runInWKWebView
46 withCString progName $ \pn -> runInWKWebView
41 handler
47 handler
42 pn
48 pn
49+ requestAuthorizationWithOptions
43 registerForRemoteNotifications
50 registerForRemoteNotifications
44− deviceTokenHandler
51+ didRegisterForRemoteNotificationsWithDeviceToken
45
52
jsaddle-wkwebview/src/Language/Javascript/JSaddle/WKWebView/Internal.hs+4−2
@@ -97,13 +97,15 @@ handlerCString c fptr = do
97 f c
97 f c
98
98
99data AppDelegateConfig = AppDelegateConfig
99data AppDelegateConfig = AppDelegateConfig
100+ { _appDelegateConfig_requestAuthorizationWithOptions :: Bool
100− { _appDelegateConfig_registerForRemoteNotifications :: Bool
101+ , _appDelegateConfig_registerForRemoteNotifications :: Bool
101 , _appDelegateConfig_didRegisterForRemoteNotificationsWithDeviceToken :: CString -> IO ()
102 , _appDelegateConfig_didRegisterForRemoteNotificationsWithDeviceToken :: CString -> IO ()
102 }
103 }
103
104
104instance Default AppDelegateConfig where
105instance Default AppDelegateConfig where
105 def = AppDelegateConfig
106 def = AppDelegateConfig
107+ { _appDelegateConfig_requestAuthorizationWithOptions = False
106− { _appDelegateConfig_registerForRemoteNotifications = False
108+ , _appDelegateConfig_registerForRemoteNotifications = False
107 , _appDelegateConfig_didRegisterForRemoteNotificationsWithDeviceToken = \_ -> return ()
109 , _appDelegateConfig_didRegisterForRemoteNotificationsWithDeviceToken = \_ -> return ()
108 }
110 }
109
111