Link in iOS app not working any more


(Mark Hunte) #8

Ok if you connect via cable to you device and run the app from xcode on it.
You can then open safari on the desktop and use the developer menu to select your connected device and the running apps webpage.

When tapping the link are any errors generated

You can also use the target button in safari desktop elements inspector.
Click the target button. Then tap you button.

This will show you what you are actually tapping in the element inspector ( desktop)


#9

there’s no iPad in my dev. menu in Safari. only iMac.


(Mark Hunte) #10

You have to run & build the app from Xcode to you iPad when linked via cable.
Once the App is launched on the iPad you then go to the menu and it should be listed.

If not , I think you need to allow it… let me check what the settings is as I do not remember of hand.


(Mark Hunte) #11

On The iPad

To Enable Safari Web Inspector on your iOS device**

  1. Open the “Settings” app on your iOS device.
  2. Navigate to “Safari > Advanced”.
  3. Turn on the " Web Inspector " toggle.

#12

yes that works.


#13

No mistakes generated. When I try to use the link from Safari on the iMac, it works. But not from the iPad. It looks like the link is blocked, thus no mistake is generated I think. Other local links in the app are working.


(Mark Hunte) #14

Not sure what you mean by local. But if you change the link to a non apple or a some other link with http and not https does it work…


#15

Local: the links in the app to other scenes etc.
http non apple makes no difference.


(Mark Hunte) #16

Just testing here now I am at my Mac.

Links to other sites work. Including Apple.

But not that type link. Did it open the App Store App or go to a webpage.

I am wondering if we should be seeing a popup saying

[ cancel| open]


#17

I tried again on the mac. Message from Safari:
cannot open itms-appss://itunes…
There is one s too many I think?

But before it did go to webpage of Apple

no popup

57


(Mark Hunte) #18

Thats an old protocol


#19

Yes, but something is changing the address, from https to itms


(Mark Hunte) #20

I get the impression that you have to use the https: but the the browser is trying to push it to the iOS AppStore app.

If open this page and I click the link above via my iPhone that what it tries to do. And I get a message alert
to open in AppStore [cancel|open]


#21

Weird. If I push the link for the second time, it opens the app store preview page. (on the mac)


(Mark Hunte) #22

So I opened the Hype project in Hype Reflect.

Go the same issue. Then used the button to open in safari.

When I click the button there I get the alert to open the App Store.

So this is looking more and more that our apps cannot handle the itms redirect protocol/scheme.

It may be a simple thing to change that but not sure…

The does seem to be a scheme management for wkwebview

https://developer.apple.com/documentation/webkit/wkwebviewconfiguration/2875766-seturlschemehandler

But you are on your own there… :sunglasses:


Anyone develop mobile apps only using Hype?
#23

Right. I will go on looking for a solution. It definitely has something to do with the wkwebview. (old app did not have the problem). Maybe someone else who is reading this thread has an answer? For now I’m on my own :disappointed_relieved:
Thank you very much for your time and efforts.


(Mark Hunte) #24

Hah,

I took a punt and got it working.

This code just checks what is about to load and then has the iOS Application itself open the link.
I figured this would bypass the web view trying…

I added the below to my iOS app code. The delegate/ same file with all the wkwebview code

  public func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Swift.Void)
    {
        
            if navigationAction.request.url != nil
            {
                
                print("\(navigationAction.request.url!)")
                //do what you need with url
               
                guard let url = URL(string: "\(navigationAction.request.url!)") else {
                    return //be safe
                }
                
                if #available(iOS 10.0, *) {
                    UIApplication.shared.open(url, options: [:], completionHandler: nil)
                } else {
                    UIApplication.shared.openURL(url)
                }
                
            }
            decisionHandler(.allow)
        
        
    }

A couple of things this code will need sanitising.
Read up in the documentation about this scheme management

Also there probably is much simpler way of doing it. Like the button posts a message to the App and that runs the open code. In fact that sounds a much better idea since there is no real learning curve about scheme prefs and you are not interfering with it.


UPDATE,

Yep the post message works and gives better control.

Simple set up which can be changed for you needs.

I gave the button the id of the url. But would suggest you give it a normal id and match against it in the hype function to then post the relevant url. Or do that in the iOS app part and just post the id.

But anyway… in my quick test version.

Button ID
romeinse-cijfers-ivxlcdm/id1116400243?l=nl&ls=1&mt=8

The Button calls a js function in Hype.

window.webkit.messageHandlers.openStore.postMessage(element.id);

In the iOS app viewDidLoad

I set the post message name. openStore

override func viewDidLoad() {
        
        super.viewDidLoad()
        
        //-- configure the WKWebView
        
        //-- init config and controller
        let wconfiguration = WKWebViewConfiguration()
        let wcontroller = WKUserContentController()
        
        //-- We must add the webkit scripts Posted messages name we expect to get from the Hype Page to the controller
      
        wcontroller.add(self, name: "openStore")
.....

And then write the handler delegate function for the post messages like so

//-- webkit Posted messages  handler delegate //-- handles messages from hype page
    func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
        
        
        if message.name == "openStore"{
            
           // anURL  = URL.init(string: message.body as! String)!
            guard let url = URL(string: "https://itunes.apple.com/us/app/\(message.body)") else {
                return //be safe
            }
            
            if #available(iOS 10.0, *) {
                UIApplication.shared.open(url, options: [:], completionHandler: nil)
            } else {
                UIApplication.shared.openURL(url)
            }
          
        }
        
         
    }

Thats it.


(Mark Hunte) #25

updated last post


#26

Wow, nice work. But:

Did I do something wrong?

This is what I have above the “override”

15


(Mark Hunte) #27

plenty.

I have posted a few post already on how to write all this but lets take this to private for the mo.