@@ -14,6 +14,7 @@ public partial class MessageViewHandler : ViewHandler<MessageView, UIView>
1414 private UIView _containerView = null ! ;
1515 private WKWebView _webView = null ! ;
1616 private NSObject ? _webViewObserver ;
17+ private UAMessageCenterNativeBridge _nativeBridge = null ! ;
1718
1819 public MessageViewHandler ( ) : base ( PropertyMapper , CommandMapper )
1920 {
@@ -27,16 +28,19 @@ protected override UIView CreatePlatformView()
2728 {
2829 _containerView = new UIView ( ) ;
2930 _containerView . BackgroundColor = UIColor . SystemBackground ;
30-
31+
3132 // Create web view with configuration
3233 var config = new WKWebViewConfiguration ( ) ;
3334 config . WebsiteDataStore = WKWebsiteDataStore . DefaultDataStore ;
3435 config . Preferences . JavaScriptEnabled = true ;
35-
36+
3637 _webView = new WKWebView ( _containerView . Bounds , config ) ;
3738 _webView . AutoresizingMask = UIViewAutoresizing . FlexibleWidth | UIViewAutoresizing . FlexibleHeight ;
38- _webView . NavigationDelegate = new MessageWebViewDelegate ( this ) ;
39-
39+
40+ _nativeBridge = new UAMessageCenterNativeBridge ( ) ;
41+ _nativeBridge . ForwardNavigationDelegate = new MessageWebViewDelegate ( this ) ;
42+ _webView . WeakNavigationDelegate = _nativeBridge . NavigationDelegate ;
43+
4044 _containerView . AddSubview ( _webView ) ;
4145
4246 return _containerView ;
@@ -59,7 +63,10 @@ protected override void DisconnectHandler(UIView platformView)
5963 _webViewObserver . Dispose ( ) ;
6064 _webViewObserver = null ;
6165 }
62-
66+
67+ _nativeBridge ? . Dispose ( ) ;
68+ _nativeBridge = null ! ;
69+
6370 _webView ? . RemoveFromSuperview ( ) ;
6471 _webView ? . Dispose ( ) ;
6572 _webView = null ;
@@ -101,22 +108,21 @@ private void LoadMessage(string messageId)
101108 var bodyUrl = message . BodyURL ;
102109 if ( bodyUrl != null )
103110 {
104- // Get authentication credentials
105- AWAirshipWrapper . GetMessageCenterUserAuth ( ( authString ) =>
111+ // Get user for native bridge and auth
112+ AWAirshipWrapper . Shared . MessageCenter . Inbox . GetUserWithCompletionHandler ( ( user ) =>
106113 {
107114 NSRunLoop . Main . InvokeOnMainThread ( ( ) =>
108115 {
109- if ( authString != null )
116+ if ( user != null )
110117 {
111- // Create request with authentication header
118+ _nativeBridge . SetMessage ( message , user ) ;
112119 var mutableRequest = new NSMutableUrlRequest ( bodyUrl ) ;
113- // The authString from basicAuthString already includes "Basic " prefix
114- mutableRequest [ "Authorization" ] = authString ;
120+ mutableRequest [ "Authorization" ] = user . BasicAuthString ;
115121 _webView . LoadRequest ( mutableRequest ) ;
116122 }
117123 else
118124 {
119- // Fallback to loading without auth if auth retrieval fails
125+ // Fallback to loading without auth if user retrieval fails
120126 var request = new NSUrlRequest ( bodyUrl ) ;
121127 _webView . LoadRequest ( request ) ;
122128 }
@@ -163,6 +169,21 @@ public void DidFailProvisionalNavigation(WKWebView webView, WKNavigation navigat
163169 {
164170 _handler . VirtualView ? . SendLoadFailed ( error . LocalizedDescription ) ;
165171 }
172+
173+ [ Export ( "webView:decidePolicyForNavigationAction:decisionHandler:" ) ]
174+ public void DecidePolicy ( WKWebView webView , WKNavigationAction navigationAction , Action < WKNavigationActionPolicy > decisionHandler )
175+ {
176+ var url = navigationAction . Request . Url ;
177+ if ( url != null && url . Scheme != "http" && url . Scheme != "https" )
178+ {
179+ decisionHandler ( WKNavigationActionPolicy . Cancel ) ;
180+ UAirship . ProcessDeepLink ( url , ( _ ) => { } ) ;
181+ }
182+ else
183+ {
184+ decisionHandler ( WKNavigationActionPolicy . Allow ) ;
185+ }
186+ }
166187 }
167188 }
168189}
0 commit comments