0

I have an application (app A) that is running in a UIWebView wrapper. I have another application (app B) that needs to be shown and accept some data from the first one. Currently we are detecting window.open (from app A) in the wrapper and creating a new controller with second WebView that slides in and contains app B.

In app A's JS code:

var appBWindow = window.open("APP_B_URL");

// Checking inside of setInterval for existence 
// of the .init() that is set by app B on its window
// when it's found we call it and pass it some data
function onAppBWindowLoad() {
   appBWindow.init(someData);
}

This works fine on both desktop and iOS Safari, but using UIWebView appBWindow.init never changes. It looks like the JSContexts was not connected the same way as they are in Safari/Chrome.

Is there a way how to make sure the appBWindow works the same as it would in a regular browser?

Petr Peller
  • 8,581
  • 10
  • 49
  • 66

1 Answers1

0

By app A and app B, are you taking about two different iOS apps? Or two different web views inside the same iOS app? I assume you're talking about the latter.

Web views in the same app share the same sessionStorage, you can use that to share data. To call functions between web views, you use the stringByEvaluatingJavaScriptFromString(_:) method.

E.g.:

Swift

let result = myWebView.stringByEvaluatingJavaScriptFromString("onAppBWindowLoad()")

where onAppBWindowLoad has this implementation:

function onAppBWindowLoad() {
    return someData
}

Note: You may find my question here useful.

Community
  • 1
  • 1
paulvs
  • 11,963
  • 3
  • 41
  • 66
  • Yes, sorry, both app A and app B are JavaScript apps inside of the WebView. I know about `stringByEvaluatingJavaScriptFromString` and I am now using it as a workaround. I also managed to implement a better solution using JSContext but I still think there should be a simple way how to "connect" these 2 WebViews so they can share JS context the same way as browser windows/tabs do when you use `var child = window.open(...)` (on the same domain) – Petr Peller May 21 '16 at 13:09