Swift WKWebView:调用方法时找不到变量错误

编程入门 行业动态 更新时间:2024-10-11 03:18:38
本文介绍了Swift WKWebView:调用方法时找不到变量错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试将 GPS 坐标传递给方法调用 setIOSNativeAppLocation.我在下面有以下代码,但出现此错误:

I am trying to pass GPS coordinates to a method call setIOSNativeAppLocation. I have the following code below but I am getting this error:

A JavaScript exception occurred" UserInfo={WKJavaScriptExceptionLineNumber=1, WKJavaScriptExceptionMessage= ReferenceError: Can't find variable: setIOSNativeAppLocation, WKJavaScriptExceptionSourceURL= mywebsite, NSLocalizedDescription= A JavaScript exception occurred, WKJavaScriptExceptionColumnNumber=24})

我不确定它是否与语法或其他任何事情有关.如果有人知道我做错了什么,我将不胜感激.

I am not sure if it has something to do with the syntax or anything else. If someone knows what I am doing wrong I would greatly appreciate it.

func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { if(myCurrentLoc != nil){ let lat = myCurrentLoc.coordinate.latitude let lon = myCurrentLoc.coordinate.longitude print(lat); print(lon); webView.evaluateJavaScript("setIOSNativeAppLocation(\(lat), \(lon));") { (result, error) in guard error == nil else { print("there was an error") print(error) return } } } }

推荐答案

我认为这可以帮助你 - 我们在这里传递参数的方式.

I think this can help you out- The way we are passing parameter here.

我们应该把它放在单引号中('\(lat)', '\(lon)') 否则它就像一个变量.

we should put it in single quote('\(lat)', '\(lon)') else it will be like a variable.

func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { if(myCurrentLoc != nil){ let lat = myCurrentLoc.coordinate.latitude let lon = myCurrentLoc.coordinate.longitude print(lat); print(lon); webView.evaluateJavaScript("setIOSNativeAppLocation('\(lat)', '\(lon)');") { (result, error) in guard error == nil else { print("there was an error") print(error) return } } } }

更多推荐

Swift WKWebView:调用方法时找不到变量错误

本文发布于:2023-11-09 03:52:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1571325.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:找不到   变量   错误   方法   Swift

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!