on master help sign in
Pass in remote notifications registration callback
commitf9caba9232a7a01094b7a4d5ff346f63595bd844 authorAli Abrar <aliabrar@gmail.com> dateSun 7 May 2017, 23:21 (9 years ago) parent23fd5bd
2 files changed+12−10
jsaddle-wkwebview/cbits-uikit/AppDelegate.m+4−4 jsaddle-wkwebview/src-ghc/Language/Javascript/JSaddle/WKWebView.hs+8−6
jsaddle-wkwebview/cbits-uikit/AppDelegate.m+4−4
@@ -9,7 +9,7 @@ extern void didRegisterForRemoteNotificationsWithDeviceTokenCallback(const char
99@end
1010
1111HsStablePtr globalHandler = 0;
12−HsStablePtr globalDeviceTokenHook = 0;
12+HsStablePtr global_didRegisterForRemoteNotificationsWithDeviceToken = 0;
1313
1414@implementation AppDelegate
1515
@@ -57,7 +57,7 @@ HsStablePtr globalDeviceTokenHook = 0;
5757
5858- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
5959 NSString *deviceTokenString = [deviceToken base64EncodedStringWithOptions: 0];
60− didRegisterForRemoteNotificationsWithDeviceTokenCallback([deviceTokenString UTF8String], globalDeviceTokenHook);
60+ didRegisterForRemoteNotificationsWithDeviceTokenCallback([deviceTokenString UTF8String], global_didRegisterForRemoteNotificationsWithDeviceToken);
6161}
6262
6363- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
@@ -66,10 +66,10 @@ HsStablePtr globalDeviceTokenHook = 0;
6666
6767@end
6868
69−void runInWKWebView(HsStablePtr handler, const char * _Nonnull progName, HsStablePtr deviceTokenHook) {
69+void runInWKWebView(HsStablePtr handler, const char * _Nonnull progName, HsStablePtr hs_didRegisterForRemoteNotificationsWithDeviceToken) {
7070 @autoreleasepool {
7171 globalHandler = handler;
72− globalDeviceTokenHook = deviceTokenHook;
72+ global_didRegisterForRemoteNotificationsWithDeviceToken = hs_didRegisterForRemoteNotificationsWithDeviceToken;
7373 const char * _Nonnull argv [] = {"", 0};
7474 UIApplicationMain(0, argv, nil, NSStringFromClass([AppDelegate class]));
7575 }
jsaddle-wkwebview/src-ghc/Language/Javascript/JSaddle/WKWebView.hs+8−6
@@ -17,21 +17,23 @@ import Language.Javascript.JSaddle (JSM)
1717foreign import ccall runInWKWebView :: StablePtr (WKWebView -> IO ()) -> CString -> StablePtr (CString -> IO ()) -> IO ()
1818
1919-- | Run JSaddle in a WKWebView
20−run :: JSM () -> IO ()
21−run f = do
20+run :: (CString -> IO ()) -> JSM () -> IO ()
21+run didRegisterForRemoteNotificationsWithDeviceToken f = do
2222 handler <- newStablePtr (jsaddleMain f)
2323 progName <- getProgName
24− deviceTokenHandler <- newStablePtr (\s -> putStrLn =<< peekCString s)
24+ deviceTokenHandler <- newStablePtr didRegisterForRemoteNotificationsWithDeviceToken
2525 withCString progName $ \pn -> runInWKWebView handler pn deviceTokenHandler
2626
2727-- | Run JSaddle in a WKWebView first loading the specified file
2828-- from the mainBundle (relative to the resourcePath).
2929runFile :: ByteString -- ^ The file to navigate to.
3030 -> ByteString -- ^ The path to allow read access to.
31− -> JSM () -> IO ()
32−runFile url allowing f = do
31+ -> (CString -> IO ())
32+ -> JSM ()
33+ -> IO ()
34+runFile url allowing didRegisterForRemoteNotificationsWithDeviceToken f = do
3335 handler <- newStablePtr (jsaddleMainFile url allowing f)
3436 progName <- getProgName
35− deviceTokenHandler <- newStablePtr (\s -> putStrLn =<< peekCString s)
37+ deviceTokenHandler <- newStablePtr didRegisterForRemoteNotificationsWithDeviceToken
3638 withCString progName $ \pn -> runInWKWebView handler pn deviceTokenHandler
3739