我正在使用PowerBI REST制作iOS应用程序。下图显示了结果。当我点击任何一个瓷砖时,我没有得到任何响应,而如果我点击 ON 红色边框(在photoshop中添加)页面仅在瓷砖包含地图时响应点击,其他瓷砖仍然没有响应。
在Mac上的浏览器中运行相同的页面一切正常,但在iOS设备上却没有。
HTML代码:
<html>
<head>
<meta name="viewport" content="initial-scale=1.0" />
<script type="text/javascript">
// listen for message to receive tile click messages.
if (window.addEventListener) {
window.addEventListener("message", receiveMessage, false);
} else {
window.attachEvent("onmessage", receiveMessage);
}
//The embedded tile posts messages for clicks to parent window. Listen and handle as appropriate
function receiveMessage(event) {
messageData = JSON.parse(event.data);
if (messageData.event == "tileClicked"){
window.webkit.messageHandlers.callbackHandler.postMessage(messageData.navigationUrl.toString());
}
}
function updateEmbedReport() {
var w = window.innerWidth - 25;
var h = window.innerHeight;
// check if the embed url was selected
var embedUrl = "";
var iframe = document.getElementById('iframe1');
iframe.src = embedUrl;
iframe.onload = postActionLoadReport;
iframe.height = h;
iframe.width = w;
}
function postActionLoadReport() {
// get the access token.
accessToken = ;
var w = window.innerWidth - 25;
var h = window.innerHeight;
// construct the post message structure
var m = { action: "loadTile", accessToken: accessToken, height: h, width: w};
message = JSON.stringify(m);
// push the message.
iframe = document.getElementById('iframe1');
iframe.contentWindow.postMessage(message, "*");
iframe.height = h;
iframe.width = w;
}
</script>
</head>
<body onload="updateEmbedReport()">
<iframe id="iframe1" width="250px" frameBorder="0" name="iframe1" height="250px" style="cursor:pointer"/>
</body>
</html>
Swift代码(我用它来让应用响应平铺点击)
private var mWebView: WKWebView?
override func awakeFromNib() {
super.awakeFromNib()
let mWebViewConfig: WKWebViewConfiguration = WKWebViewConfiguration()
mWebViewConfig.userContentController.addScriptMessageHandler(self, name: "callbackHandler")
mWebViewConfig.preferences.javaScriptEnabled = true
mWebViewConfig.preferences.javaScriptCanOpenWindowsAutomatically = true
self.mWebView = WKWebView(frame: self.frame, configuration: mWebViewConfig)
//self.mWebView!.scrollView.scrollEnabled = false
self.addSubview(self.mWebView!)
}
func setData(url: String, tileClick: ITileClick){
self.mTileClick = tileClick
let page: String = (InstanceReferences.mPowerBIHandler?.GetPage(InstanceReferences.mAuthenticationToken!, EmbedURL: url, ReportPage: false))!
self.mWebView?.loadHTMLString(page, baseURL: NSURL(string: url)!)
}
func userContentController(userContentController: WKUserContentController, didReceiveScriptMessage message: WKScriptMessage) {
print("iniside")
if message.name == "callbackHandler" {
self.mTileClick?.OnTilePageClick("\(message.body)")
} }
注意:在Android应用程序中使用相同的HTML页面,一切正常,没有问题。
任何帮助都会很棒。
答案 0 :(得分:0)
嵌入式页面中似乎存在一个错误,导致它无法检测iOS点击。我相信由于跨域限制,您无法在最终解决此问题。
您可以通过保存tileLoaded事件(在tile加载时触发)提供的导航URL以及检测iOS中的点击(在WKWebView上使用手势识别器)来解决此问题。