turbolinks / turbolinks-ios

Native iOS adapter for building hybrid apps with Turbolinks 5
MIT License
881 stars 92 forks source link

Passing data to and from the native client #53

Closed rayfix closed 8 years ago

rayfix commented 8 years ago

Turbolinks is an interesting hybrid platform because IIUC, it allows you to start quickly with web views and incrementally adopt native components on an as needed basis.

I have been running into some problems accomplishing this but it may just be a lack of understanding on my part or not reading the proper documentation. I feel I am a reasonably experienced Swift developer but have a fragile understanding of WebKit and Javascript.

After a user authenticates, I want to be able to grab a header in the token that comes back from the POST request so that I can issue my own native REST requests. I am not sure what the proper way to accomplish this is. Am I supposed do something in the visitDidComplete callback and possibly inject some Javascript into the WebView so I can serialize the token out?

It would be nice if there were documentation or something in the sample app that showed how to do this. I find the current sample app lacking on details here. Perhaps there currently is not a mechanism for doing this kind of data transfer. If so, would there be interest to add it? I am willing to work on it if I can get some help pointing me in the right direction about what approach would be acceptable.

Also, if this is not the appropriate place to discuss this, please let me know. Thank you!!

zachwaugh commented 8 years ago

Hi @rayfix, WKWebView has a few different methods for communicating from native -> web (webView.evaluateJavaScript) and from web -> native (WKScriptMessageHandler). You could use those for transferring data between the two.

39 has a few solutions to this problem, and I just added a comment with how we handle it in Basecamp - https://github.com/turbolinks/turbolinks-ios/issues/39#issuecomment-237669770. Going to close this issue to keep the discussion in one place.