0

Now, I embed an HTML via WKWebView. If a user clicks the a element, I want to open the Apple Map APP. It seems nothing to happen, only the background color changed. My code:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        a {
            display: block;
            font-size: 20px;
            width: 200px;
            height: 100px;
            margin: 100px auto;
            text-align: center;
        }
    </style>
</head>
<body>

<h1>open the  apple map</h1>

<a href="maps:ll=38.897096,-77.036545" class="context-block-button map-button" id="map-button-1"><i class="ss-map icon-left"></i><span>Open in map (maps:)</span></a>

</body>
<script src="../js/jquery.min.js"></script>
<script>
    $('body').on('click','a',function () {
            $('body').css('background-color','blue');
      window.location.href = " http://maps.apple.com/?q=Mexican+Restaurant&sll=50.894967,4.341626&z=10&t=s";
    })
</script>
</html>

In the safari, I copy " http://maps.apple.com/?q=Mexican+Restaurant&sll=50.894967,4.341626&z=10&t=s".Then the safari will open the Apple App on Mac.

Must I use the Swift4 API to open the Apple Map App? One more thing, if the solution must change the info.plist or change the App target setting, thank you for writing this for me.

jiexishede
  • 2,473
  • 6
  • 38
  • 54

1 Answers1

0

Yes, you need to use Swift API and need to implement WKNavigationDelegate, add decidePolicyForNavigationAction method.

Check this answer from another thread.

mitesh
  • 136
  • 5