iOS WKWebView Handle File Download - ios

I am facing the following problem:
In a web interface, file downloads are triggered with an anchor tag, like this:
<a href="/bla/blabla" download>..</a>
While Safari browser can handle this request and open a dialogue to handle the file, WKWebView treats this just as an ordinary link and does nothing with it. I want to be able to get the file handler dialogue that is normally there when using Safari.
Right now there are 2 problems and I do not see an opening there yet:
I can not detect a click on the element as it is treated just as a normal link. And I can not rely on the URL parameters to detect if it is a file since that is not constantly true.
Even if the URL is defined as a one leading to a file, I can not pass it to Safari since it does not share session info and cookies with my app's WKWebView.
Therefore, I would like to know if there is any opening in handling files in iOS WKWebView. Thank you.

Related

How can I prevent opening multiple browser windows with deep links in PWA?

Is it possible to make sure that (deep) links don't open a new browser window?
Use case would be e.g. QR Codes or NFC tags that contain some kind of identifier along with a URL/deep link URL.
e.g. www.example.com/mypwa/game=ID
The idea in this case would be that an asset linked to ID would become available in the app.
When you want to do that repeatedly, currently both Chrome on Android and Safari on iOS (as Standard Browser) open a new tab for each tapped NFC tag, confusing the user.
Is it possible for a PWA to check if it is already running in another tab, and if yes, take over the URL parameter (ID) and work with it ?

Custom URL Scheme Failing within own app

I have a custom URL scheme that I've been using successfully in my app during development for a few months now. We have some web pages that we load in some WKWebViews, and some of those links use our custom URL scheme to call our own app, which then takes action based on those URLs.
Today I deleted the app on my phone and reinstalled it in an attempt to work out a different bug I was having.
Suddenly, tapping on these links does nothing. I cannot find an error being thrown anywhere. Not in the console, not anywhere. I've attempted to dig way down into the various WKWebView delegate methods, but it seems like WKWebView isn't even trying to do anything with these URLs.
However, if I attempt to open one of these URLs in Safari, Safari will ask me if I want to open the URL in my app, which will then load and handle the URL.
Has anyone else seen this? Or have any ideas of where to look to track this down?
I've tried:
Removing and re-adding the URL scheme in my info.plist
Changing the scheme to a new value, then removing it and adding it back in info.plist
Deleting the app
Rebooting my phone
The issue has turned out to be something related to Turbolinks. Somehow there are situations where the page load event isn't firing, and Turbolinks then does not call code we need to activate some elements on the page.

Custom URL scheme without confirmation prompt (Swift)

I've found two options to open my app from a Safari web page: a custom URL scheme created in my app project's Info.plist or Apple's Universal Linking. Obviously the custom URL scheme is the easiest one to set up, but the problem I'm having with this is that Safari shows a confirmation window asking "Open myapp?" first and the user has to tap OK before the app actually opens. I want my app to open automatically as the scheme is opened, and I'm being told the only way to do this is through Universal Linking (please correct me if this is not true). If this is true, however, I would like to know if it's possible in any way to put the required apple-app-site-association file on a http:// domain instead of https://? According the official Apple documentation the format of a correct Universal Link starts explicitly with https:// but my domain name can't be loaded on https:// without redirecting a few times and that messes up the web services I've written to execute other tasks in my app. The two main questions I'm left with after this issue:
1) Is it really impossible to work around the confirmation prompt using a custom URL scheme (myscheme://)? If it's not impossible, how can I do this?
2) If I have to use Apple Universal Linking, can I use a http:// domain? If so, how do I do it? Right now if I load up the universal link, it just shows the dictionary inside the apple-app-site-association file, which I'm pretty sure is not supposed to happen. I'm told it's supposed to send a NSUserActivity object to my app delegate. How can I accomplish this with a http:// link?
It is not possible to trigger a custom URI scheme without showing an alert to the user. This used to be possible in iOS 8, but iOS 9 started showing the alert for all apps. And iOS 10.3 has extended that even to the App Store itself. You cannot bypass this. Universal Links were created to replace URI schemes for this behavior, so you do need to use them instead.
From your description, I believe you may be misunderstanding how Universal Links work. To answer the literal questions you asked first, no the Universal Link URL itself does not need to be on the https:// protocol, and yes, the apple-app-site-association must be served over https:// without redirects.
However, it sounds like you're trying to serve the content of the apple-app-site-association file for every Universal Link. That is not the correct implementation — the AASA file is hosted only at https://example.com/apple-app-site-association, and iOS automatically retrieves it when the app is installed. After that, any URL on example.com that matches the criteria in the AASA file will be eligible for Universal Links.
All of that said, you really don't want to built out this system on your own. I suggest looking into Firebase Dynamic Links or Branch.io (full disclosure: I'm on the Branch team).
Is it really impossible to work around the confirmation prompt using a custom URL scheme (myscheme://)? If it's not impossible, how can I do this?
That is possible with some hacky tricks and BAD user experience. It requires user to press "add to home screen" button, so I don't recommend this solution in most cases.
set your app scheme like myapp
create the following html file and put it into the web
window.onload = function() {
if (("standalone" in window.navigator) && window.navigator.standalone) {
window.location.href = 'myapp://open'
}
}
open the html file with safari and "add to home screen"
open the home screen icon and your native app will launch
The point is the meta tag.
<meta name="apple-mobile-web-app-capable" content="yes" />
Without this, safari will launch and confirmation prompt will appear.

iOS: Open a registered open URL from within the same app

I am running into a situation which I am not sure is possible from technical/design point of view. Please advise.
Here is what I need:
I have an open URL registered for my native iOS app. I expect a request ID to be passed along with it and once hit I open that request.
From within my native iOS app, I need to open a web page in the webview. This page has few buttons in it.
A tap on the button in the webview should open the request inside my app. So, I want to trigger the registered open URL in step #1.
Web page data is dynamic and will change on the fly.
Is this a feasible design. Shall I consider something else.
Any advise/pointers will be appreciated.
This should be possible. Here's a though:
1: Implement the UIWebview delegate method shouldStartLoadWithRequest.
2: when you intercept that your webview is attempting to access the url yourapp://blah-blah-blah you can return NO instead dip into your appdelegate can manually call the function handleOpenURL.
I've seen something similar in the past with supporting oAuth (I believe it was with instagram) within one of our apps. We basically loaded up the login page in a UIWebview and then when we detected the the post login redirect we parsed the oAuth token from the url and called it good.
Good luck

StageWebView issue on ipad

I am using stageWebView for showing webpage in my mobile app but don't know how to move back to my app once it gets loaded. In application descriptor file, I had already registered custom uri scheme (myapp://) for IOS devices and from the loaded page inside stageWebView, I was trying to call following URL myapp://webcam. But nothing had happened. It neither called LOCATION_CHANGE event of StageWebView not called INVOKE_EVENT of nativeapplication.
How can I fix this issue?
Thanks in advance,
Mamta
Custom URIs don't work in StageWebView (adobe help page)
Instead of a custom URI, use a hash tag and listen for Event.COMPLETE events on the StageWebView.
Webcam
instead of
Webcam
You'll get a Event.COMPLETE event when they click the link and can then check the StageWebView.location for a location hash.

Resources