skip to Main Content

I’m using PowerBI REST to make an iOS App. Image below shows the result. When I click on any of the tiles I get no response, while if I click ON the red border (added in photoshop) Page respond to the click only if the tile includes a map, other tiles still no response.

Running the same page in a browser on Mac everything works, but on an iOS device it doesn’t.

HTML Code:

<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 code (which I use to make the app respond to tile click)

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)")
}   }

Note: Used the same HTML page in android app and everything is working without issues.

enter image description here

Any help would be great.

2

Answers


  1. Have you been able to use any of the drill down options using the Power BI App on iphone?

    Login or Signup to reply.
  2. There seems to be a bug in the embedded page which prevents it from detecting iOS taps. I believe you won’t be able to solve this on your end due to cross-domain restrictions.

    You can workaround this problem by saving the navigation URL provided to you by the tileLoaded event (fired on tile load), and detecting taps in iOS (Using a gesture recognizer on the WKWebView).

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search