xiubojin / JXBWKWebView

An component WebView for iOS base on WKWebView
MIT License
736 stars 115 forks source link

原生界面push到webview的时候,怎么把值传给service #10

Closed GreatLiyi closed 5 years ago

GreatLiyi commented 5 years ago

先把原生界面的数据传到H5,然后H5再传到service,这种做法太笨拙了

xiubojin commented 5 years ago

什么意思?

GreatLiyi commented 5 years ago

什么意思? 原生界面push到webview的时候,怎么把值传给service层,service层是和js交互的

xiubojin commented 5 years ago

native主动和web交互不能依靠service,得通过webview执行那个js脚本api给web传值。所以你至少得等js资源加载完成之后才能执行js脚本。

xiubojin commented 5 years ago

或者你在service层把方法准备好,等web资源都加载完成后让web主动调用你的service方法去拿数据。

GreatLiyi commented 5 years ago

或者你在service层把方法准备好,等web资源都加载完成后让web主动调用你的service方法去拿数据。

问题是service层怎么获取native的数据,是不是native把值传到webview,然后获取topviewcontroller的数据吗,活着通过单例传值

xiubojin commented 5 years ago

两个办法: 1、web加载完成后,你获取到当前的webview然后执行js脚本,把值传给web。 2、在service里,想办法获取到数据(单例、数据库、归档什么都可以),再传给web。

GreatLiyi commented 5 years ago

两个办法: 1、web加载完成后,你获取到当前的webview然后执行js脚本,把值传给web。 2、在service里,想办法获取到数据(单例、数据库、归档什么都可以),再传给web。

好的,谢谢哈,可以close了