on master help sign in
Pass in remote notifications registration callback
f9caba9Ali Abrar
jsaddle-wkwebview/cbits-uikit/AppDelegate.m+4−4
@@ -9,7 +9,7 @@ extern void didRegisterForRemoteNotificationsWithDeviceTokenCallback(const char
9@end
9@end
10
10
11HsStablePtr globalHandler = 0;
11HsStablePtr globalHandler = 0;
12−HsStablePtr globalDeviceTokenHook = 0;
12+HsStablePtr global_didRegisterForRemoteNotificationsWithDeviceToken = 0;
13
13
14@implementation AppDelegate
14@implementation AppDelegate
15
15
@@ -57,7 +57,7 @@ HsStablePtr globalDeviceTokenHook = 0;
57
57
58- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
58- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
59 NSString *deviceTokenString = [deviceToken base64EncodedStringWithOptions: 0];
59 NSString *deviceTokenString = [deviceToken base64EncodedStringWithOptions: 0];
60− didRegisterForRemoteNotificationsWithDeviceTokenCallback([deviceTokenString UTF8String], globalDeviceTokenHook);
60+ didRegisterForRemoteNotificationsWithDeviceTokenCallback([deviceTokenString UTF8String], global_didRegisterForRemoteNotificationsWithDeviceToken);
61}
61}
62
62
63- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
63- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
@@ -66,10 +66,10 @@ HsStablePtr globalDeviceTokenHook = 0;
66
66
67@end
67@end
68
68
69−void runInWKWebView(HsStablePtr handler, const char * _Nonnull progName, HsStablePtr deviceTokenHook) {
69+void runInWKWebView(HsStablePtr handler, const char * _Nonnull progName, HsStablePtr hs_didRegisterForRemoteNotificationsWithDeviceToken) {
70 @autoreleasepool {
70 @autoreleasepool {
71 globalHandler = handler;
71 globalHandler = handler;
72− globalDeviceTokenHook = deviceTokenHook;
72+ global_didRegisterForRemoteNotificationsWithDeviceToken = hs_didRegisterForRemoteNotificationsWithDeviceToken;
73 const char * _Nonnull argv [] = {"", 0};
73 const char * _Nonnull argv [] = {"", 0};
74 UIApplicationMain(0, argv, nil, NSStringFromClass([AppDelegate class]));
74 UIApplicationMain(0, argv, nil, NSStringFromClass([AppDelegate class]));
75 }
75 }
jsaddle-wkwebview/src-ghc/Language/Javascript/JSaddle/WKWebView.hs+8−6
@@ -17,21 +17,23 @@ import Language.Javascript.JSaddle (JSM)
17foreign import ccall runInWKWebView :: StablePtr (WKWebView -> IO ()) -> CString -> StablePtr (CString -> IO ()) -> IO ()
17foreign import ccall runInWKWebView :: StablePtr (WKWebView -> IO ()) -> CString -> StablePtr (CString -> IO ()) -> IO ()
18
18
19-- | Run JSaddle in a WKWebView
19-- | Run JSaddle in a WKWebView
20−run :: JSM () -> IO ()
20+run :: (CString -> IO ()) -> JSM () -> IO ()
21−run f = do
21+run didRegisterForRemoteNotificationsWithDeviceToken f = do
22 handler <- newStablePtr (jsaddleMain f)
22 handler <- newStablePtr (jsaddleMain f)
23 progName <- getProgName
23 progName <- getProgName
24− deviceTokenHandler <- newStablePtr (\s -> putStrLn =<< peekCString s)
24+ deviceTokenHandler <- newStablePtr didRegisterForRemoteNotificationsWithDeviceToken
25 withCString progName $ \pn -> runInWKWebView handler pn deviceTokenHandler
25 withCString progName $ \pn -> runInWKWebView handler pn deviceTokenHandler
26
26
27-- | Run JSaddle in a WKWebView first loading the specified file
27-- | Run JSaddle in a WKWebView first loading the specified file
28-- from the mainBundle (relative to the resourcePath).
28-- from the mainBundle (relative to the resourcePath).
29runFile :: ByteString -- ^ The file to navigate to.
29runFile :: ByteString -- ^ The file to navigate to.
30 -> ByteString -- ^ The path to allow read access to.
30 -> ByteString -- ^ The path to allow read access to.
31+ -> (CString -> IO ())
31− -> JSM () -> IO ()
32+ -> JSM ()
33+ -> IO ()
32−runFile url allowing f = do
34+runFile url allowing didRegisterForRemoteNotificationsWithDeviceToken f = do
33 handler <- newStablePtr (jsaddleMainFile url allowing f)
35 handler <- newStablePtr (jsaddleMainFile url allowing f)
34 progName <- getProgName
36 progName <- getProgName
35− deviceTokenHandler <- newStablePtr (\s -> putStrLn =<< peekCString s)
37+ deviceTokenHandler <- newStablePtr didRegisterForRemoteNotificationsWithDeviceToken
36 withCString progName $ \pn -> runInWKWebView handler pn deviceTokenHandler
38 withCString progName $ \pn -> runInWKWebView handler pn deviceTokenHandler
37
39