ShawnFoo / SwiftWebViewBridge

Swift version of WebViewJavascriptBridge with more simplified and friendly methods to handle messages between Swift and JS in UIWebViews
MIT License
137 stars 34 forks source link

Multiple pieces of data #20

Closed nah2015 closed 6 years ago

nah2015 commented 6 years ago

Hello, I have been using this to send one piece of data fora while now and I am very happy with it.

I am having an issue understanding how to send more than one piece of data.

I have two javascript variables in HTML file. I wish to send them accross bridge and apply their values to variables in my .swift file

Currently with just one, I initialize the bridge and then make

myvariable = data as! String

This doesn't seem to work for multiple pieces of data though as each gets passed through as "data"

Any insight? Thank you!

ShawnFoo commented 6 years ago
        Hi,nah,what's the system version when u meet this issue? If u sent two messages to Swift from JS, there should have been 2 messages arrived in Swift.  If what you mean is sendind two fields one time to Swift, I think you have to add two fields behind 'data' field. For instance, {'data': {'field1': value1, 'field2': value2}}.I am taking a holiday right now, without my macbook around. It will be great if u can upload the code block in case i misunderstand the issue. Thank you.

        On 09/23/2017 10:02, nah2015 wrote: Hello, I have been using this to send one piece of data fora  while now and I am very happy with it.

I am having an issue understanding how to send more than one piece of data. I have two javascript variables in HTML file. I wish to send them accross bridge and apply their values to variables in my .swift file Currently with just one, I initialize the bridge and then make myvariable = data as! String This doesn't seem to work for multiple pieces of data though as each gets passed through as "data" Any insight? Thank you!

—You are receiving this because you are subscribed to this thread.Reply to this email directly, view it on GitHub, or mute the thread.

{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/ShawnFoo/SwiftWebViewBridge","title":"ShawnFoo/SwiftWebViewBridge","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/ShawnFoo/SwiftWebViewBridge"}},"updates":{"snippets":[{"icon":"DESCRIPTION","message":"Multiple pieces of data (#20)"}],"action":{"name":"View Issue","url":"https://github.com/ShawnFoo/SwiftWebViewBridge/issues/20"}}}

nah2015 commented 6 years ago

Thank you for your very fast response Shawn!

I figured it out not too long after making this post and it was working great

Unfortunately my issue has changed into something else now, as I have upgraded to XCode 9.0 and I am getting the following error for SwiftWebViewBridge when building

Module compiled with Swift 3.1 cannot be imported in Swift 3.2: /Users/me/Library/Developer/Xcode/DerivedData/app-aniboirsgqgsvqatrtgzvvrevrfr/Build/Products/Debug-iphoneos/SwiftWebViewBridge/SwiftWebViewBridge.framework/Modules/SwiftWebViewBridge.swiftmodule/arm64.swiftmodule

nah2015 commented 6 years ago

Actually - scratch that. It seems that running Product -> Clean has fixed the error mentioned above.

Thanks again for this awesome module