on master help sign in
Add didFailToRegisterForRemoteNotificationsWithError to AppDelegateConfig
9dbfcb1Ali Abrar
jsaddle-wkwebview/cbits-uikit/AppDelegate.m+6−2
@@ -16,6 +16,7 @@ BOOL global_requestAuthorizationOptionAlert = NO;
16BOOL global_requestAuthorizationOptionCarPlay = NO;
16BOOL global_requestAuthorizationOptionCarPlay = NO;
17BOOL global_registerForRemoteNotifications = NO;
17BOOL global_registerForRemoteNotifications = NO;
18HsStablePtr global_didRegisterForRemoteNotificationsWithDeviceToken = 0;
18HsStablePtr global_didRegisterForRemoteNotificationsWithDeviceToken = 0;
19+HsStablePtr global_didFailToRegisterForRemoteNotificationsWithError = 0;
19
20
20@implementation AppDelegate
21@implementation AppDelegate
21
22
@@ -83,7 +84,8 @@ HsStablePtr global_didRegisterForRemoteNotificationsWithDeviceToken = 0;
83}
84}
84
85
85- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
86- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
86− // Called when remote notification registration failed
87+ NSString *errorString = [error localizedDescription];
88+ handlerCString([errorString UTF8String], global_didFailToRegisterForRemoteNotificationsWithError);
87}
89}
88
90
89@end
91@end
@@ -96,7 +98,8 @@ void runInWKWebView(HsStablePtr handler,
96 const BOOL hs_requestAuthorizationOptionAlert,
98 const BOOL hs_requestAuthorizationOptionAlert,
97 const BOOL hs_requestAuthorizationOptionCarPlay,
99 const BOOL hs_requestAuthorizationOptionCarPlay,
98 const BOOL hs_registerForRemoteNotifications,
100 const BOOL hs_registerForRemoteNotifications,
99− HsStablePtr hs_didRegisterForRemoteNotificationsWithDeviceToken) {
101+ HsStablePtr hs_didRegisterForRemoteNotificationsWithDeviceToken,
102+ HsStablePtr hs_didFailToRegisterForRemoteNotificationsWithError) {
100 @autoreleasepool {
103 @autoreleasepool {
101 globalHandler = handler;
104 globalHandler = handler;
102 global_requestAuthorizationWithOptions = hs_requestAuthorizationWithOptions;
105 global_requestAuthorizationWithOptions = hs_requestAuthorizationWithOptions;
@@ -106,6 +109,7 @@ void runInWKWebView(HsStablePtr handler,
106 global_requestAuthorizationOptionCarPlay = hs_requestAuthorizationOptionCarPlay;
109 global_requestAuthorizationOptionCarPlay = hs_requestAuthorizationOptionCarPlay;
107 global_registerForRemoteNotifications = hs_registerForRemoteNotifications;
110 global_registerForRemoteNotifications = hs_registerForRemoteNotifications;
108 global_didRegisterForRemoteNotificationsWithDeviceToken = hs_didRegisterForRemoteNotificationsWithDeviceToken;
111 global_didRegisterForRemoteNotificationsWithDeviceToken = hs_didRegisterForRemoteNotificationsWithDeviceToken;
112+ global_didFailToRegisterForRemoteNotificationsWithError = hs_didFailToRegisterForRemoteNotificationsWithError;
109 const char * _Nonnull argv [] = {"", 0};
113 const char * _Nonnull argv [] = {"", 0};
110 UIApplicationMain(0, argv, nil, NSStringFromClass([AppDelegate class]));
114 UIApplicationMain(0, argv, nil, NSStringFromClass([AppDelegate class]));
111 }
115 }
jsaddle-wkwebview/src-ghc/Language/Javascript/JSaddle/WKWebView.hs+28−18
@@ -21,16 +21,18 @@ import Foreign.C.Types
21import Foreign.StablePtr (StablePtr, newStablePtr)
21import Foreign.StablePtr (StablePtr, newStablePtr)
22import Language.Javascript.JSaddle (JSM)
22import Language.Javascript.JSaddle (JSM)
23
23
24−foreign import ccall runInWKWebView :: StablePtr (WKWebView -> IO ())
24+foreign import ccall runInWKWebView
25+ :: StablePtr (WKWebView -> IO ())
25− -> CString
26+ -> CString
26− -> CChar -- whether to run requestAuthorizationWithOptions
27+ -> CChar -- whether to run requestAuthorizationWithOptions
27− -> CChar -- Ask for Badge authorization
28+ -> CChar -- Ask for Badge authorization
28− -> CChar -- Ask for Sound authorization
29+ -> CChar -- Ask for Sound authorization
29− -> CChar -- Ask for Alert authorization
30+ -> CChar -- Ask for Alert authorization
30− -> CChar -- Ask for CarPlay authorization
31+ -> CChar -- Ask for CarPlay authorization
31− -> CChar -- registerForRemoteNotifications
32+ -> CChar -- registerForRemoteNotifications
32− -> StablePtr (CString -> IO ()) -- didRegisterForRemoteNotificationsWithDeviceToken
33+ -> StablePtr (CString -> IO ()) -- didRegisterForRemoteNotificationsWithDeviceToken
34+ -> StablePtr (CString -> IO ()) -- didFailToRegisterForRemoteNotificationsWithError
33− -> IO ()
35+ -> IO ()
34
36
35
37
36data AppDelegateConfig = AppDelegateConfig
38data AppDelegateConfig = AppDelegateConfig
@@ -52,6 +54,7 @@ data AppDelegateNotificationConfig = AppDelegateNotificationConfig
52 { _appDelegateNotificationConfig_requestAuthorizationWithOptions :: Maybe (Set AuthorizationOption)
54 { _appDelegateNotificationConfig_requestAuthorizationWithOptions :: Maybe (Set AuthorizationOption)
53 , _appDelegateNotificationConfig_registerForRemoteNotifications :: Bool
55 , _appDelegateNotificationConfig_registerForRemoteNotifications :: Bool
54 , _appDelegateNotificationConfig_didRegisterForRemoteNotificationsWithDeviceToken :: CString -> IO ()
56 , _appDelegateNotificationConfig_didRegisterForRemoteNotificationsWithDeviceToken :: CString -> IO ()
57+ , _appDelegateNotificationConfig_didFailToRegisterForRemoteNotificationsWithError :: CString -> IO ()
55 }
58 }
56
59
57instance Default AppDelegateNotificationConfig where
60instance Default AppDelegateNotificationConfig where
@@ -59,16 +62,13 @@ instance Default AppDelegateNotificationConfig where
59 { _appDelegateNotificationConfig_requestAuthorizationWithOptions = Nothing
62 { _appDelegateNotificationConfig_requestAuthorizationWithOptions = Nothing
60 , _appDelegateNotificationConfig_registerForRemoteNotifications = False
63 , _appDelegateNotificationConfig_registerForRemoteNotifications = False
61 , _appDelegateNotificationConfig_didRegisterForRemoteNotificationsWithDeviceToken = \_ -> return ()
64 , _appDelegateNotificationConfig_didRegisterForRemoteNotificationsWithDeviceToken = \_ -> return ()
65+ , _appDelegateNotificationConfig_didFailToRegisterForRemoteNotificationsWithError = \_ -> return ()
62 }
66 }
63
67
64
68
65-- | Run JSaddle in a WKWebView
69-- | Run JSaddle in a WKWebView
66−run :: (CString -> IO ()) -> JSM () -> IO ()
70+run :: AppDelegateConfig -> JSM () -> IO ()
67−run didRegisterForRemoteNotificationsWithDeviceToken f = do
71+run = run' Nothing
68− handler <- newStablePtr (jsaddleMain f)
69− progName <- getProgName
70− deviceTokenHandler <- newStablePtr didRegisterForRemoteNotificationsWithDeviceToken
71− withCString progName $ \pn -> runInWKWebView handler pn 1 1 1 1 1 1 deviceTokenHandler
72
72
73-- | Run JSaddle in a WKWebView first loading the specified file
73-- | Run JSaddle in a WKWebView first loading the specified file
74-- from the mainBundle (relative to the resourcePath).
74-- from the mainBundle (relative to the resourcePath).
@@ -77,8 +77,16 @@ runFile :: ByteString -- ^ The file to navigate to.
77 -> AppDelegateConfig
77 -> AppDelegateConfig
78 -> JSM ()
78 -> JSM ()
79 -> IO ()
79 -> IO ()
80−runFile url allowing cfg f = do
80+runFile url allowing = run' $ Just (url, allowing)
81+
82+run' :: Maybe (ByteString, ByteString)
83+ -> AppDelegateConfig
84+ -> JSM ()
85+ -> IO ()
86+run' mUrl cfg f = do
87+ handler <- case mUrl of
81− handler <- newStablePtr (jsaddleMainFile url allowing f)
88+ Just (url, allowing) -> newStablePtr (jsaddleMainFile url allowing f)
89+ Nothing -> newStablePtr (jsaddleMain f)
82 progName <- getProgName
90 progName <- getProgName
83 let ncfg = _appDelegateConfig_appDelegateNotificationConfig cfg
91 let ncfg = _appDelegateConfig_appDelegateNotificationConfig cfg
84 (requestAuthorizationWithOptions, authorizationOptions) =
92 (requestAuthorizationWithOptions, authorizationOptions) =
@@ -87,6 +95,7 @@ runFile url allowing cfg f = do
87 Just opts -> (True, opts)
95 Just opts -> (True, opts)
88 registerForRemoteNotifications = _appDelegateNotificationConfig_registerForRemoteNotifications ncfg
96 registerForRemoteNotifications = _appDelegateNotificationConfig_registerForRemoteNotifications ncfg
89 didRegisterForRemoteNotificationsWithDeviceToken <- newStablePtr $ _appDelegateNotificationConfig_didRegisterForRemoteNotificationsWithDeviceToken ncfg
97 didRegisterForRemoteNotificationsWithDeviceToken <- newStablePtr $ _appDelegateNotificationConfig_didRegisterForRemoteNotificationsWithDeviceToken ncfg
98+ didFailToRegisterForRemoteNotificationsWithError <- newStablePtr $ _appDelegateNotificationConfig_didFailToRegisterForRemoteNotificationsWithError ncfg
90 withCString progName $ \pn -> runInWKWebView
99 withCString progName $ \pn -> runInWKWebView
91 handler
100 handler
92 pn
101 pn
@@ -97,3 +106,4 @@ runFile url allowing cfg f = do
97 (boolToCChar $ Set.member AuthorizationOption_CarPlay authorizationOptions)
106 (boolToCChar $ Set.member AuthorizationOption_CarPlay authorizationOptions)
98 (boolToCChar registerForRemoteNotifications)
107 (boolToCChar registerForRemoteNotifications)
99 didRegisterForRemoteNotificationsWithDeviceToken
108 didRegisterForRemoteNotificationsWithDeviceToken
109+ didFailToRegisterForRemoteNotificationsWithError