Capture print requests from a UIWebView - ios

I have an app that is a wrapper for a website. It allows us to use a third party web app for some services in our business. One of the things it will do is print labels. In mobile safari if I do the setup and press print, the request is processed in safari and I can print without any issue using air print.
Inside of my custom app the uiwebview makes the same request however nothing is sent to the printer. I have added a popover that I can manually submit a print job, but I can't manage to capture any print requests that come from the webview.

I was able to get in touch with an Apple engineer who confirmed it is impossible to receive the window.print request from UIWebView. For my purposes, I just use javascript to change the window.print function to a command that will tell me the print request was made, and then I can print the part of the webview that I needed.

Related

Submitting login form in WKWebView inside an iOS share extension causes the share extension to close

Background:
We are building a React Native app which allows users to create posts that include a quote from a blog post or news article. To achieve this, we have built a share extension, which displays a React Native view inside a modal. Inside the RN view we are using react-native-webview (which renders as a WKWebView on iOS), to display the page that was shared, allowing the user to select some text on the page (which is fed back to our app via an injected content script), and continue to create a post.
The problem:
Some news sites that our users want to share from have paywalls, e.g. FT, NY Times etc. - on these sites the user has to log in inside the webview. It's not ideal, but once they have logged in, as we have cookies enabled on the webview, their session will be remembered. This solution works well on Android, and works well on iOS when sharing from Safari.
When sharing from an app on iOS however, once the user submits the login form inside the webview, the share extension closes, taking the user back to the app that initiated the share action.
Here is a video demonstration of the issue occurring in the Guardian app:
https://www.youtube.com/watch?v=DFnh1x3j4xs
Observations:
When observing requests that occur within the webview using the onShouldStartLoadWithRequest prop of the WebView component, upon submitting the login form, there are two requests where iOS reports the navigationType as formSubmitted.
By checking the navigationType inside of the onShouldStartLoadWithRequest method, I was able to allow the first formSubmitted request to go through, but cancel the subsequent one. This prevented the share extension from closing, but upon clicking a link to go back to the home page, the share extension was closed.
My current theory is that the app which initiates the share, is somehow hooking into the form submit event, as these apps generally use webviews for their own login process - so although this webview is running in our own process, perhaps the app still somehow hooks into the process.
It is worth noting that this behaviour is inconsistent between news apps, presumably due to differences in the way they handle their login process.
Initially this issue was occurring in the BBC app as well, but at some point stopped occurring without us making any changes, so it is somewhat intermittent, or perhaps based on stored data/cookies.
Summary
We would like to fully understand why this behaviour occurs, and we're hoping there is a solution or workaround that will prevent the share extension from closing when the login form is submitted.

No audio for 2nd & subsequent calls using Opentok in iOS

We have a video chat single page application developed in AngularJS that connects Callers with Receivers using OpenTok (Tokbox). Receivers must use computers but Callers can use iOS or Android devices. However, when a Caller uses iOS, the first call is fine, but the 2nd and subsequent calls in the same session result in audio being lost for the iPhone user.
The application consists of a Homepage, Profile pages, Dashboards and Call Screens. A Caller initiates a video chat with a Receiver in the following way:
Types in Receiver’s Profile page and logs in
Clicks ‘Call’ from Receiver’sProfile page, lands on Call Screen & gives permission to use camera etc.
Clicks ‘Call’ again and video/audio chat starts
Clicks ‘End call’ and lands on their dashboard page
Then, if the Caller chooses to call Receiver again, the Caller:
Either clicks back button or retypes Receiver’s URL to return to Receiver’s profile page
Clicks ‘Call’ from Receiver’s Profile page, lands on call screen
Clicks ‘Call’ again and video starts - but usually (although not always) cannot hear any audio on the iPhone
After extensive testing, only 3 things happen with 100% consistency:
If, after a chat, the Caller goes to the Homepage and then returns to Profile page, the audio will never work, no matter how many times you try.
If, however, the Caller types in a URL of an entirely different site, and returns to the profile page, the problem is always reset: the Caller will definitely have audio for the next call, after which the whole problem starts again.
Closing and initiating a new window also resets the issue.
Aside from these certainties, there are many other variables that may or may not produce the issue (and how often), including:
What version of iOS the Caller is using
Whether the Caller uses the back button or types in the URL to go from dashboard to profile page after a call
Whether the Caller simply clicks the back button or holds and chooses the Profile page URL
Whether the Caller clicks around in their Dashboard or not before returning to Profile page
Tokbox session logs show that both published streams contain both audio and video, and no errors are reported. The audio is lost within iOS.
We have no problems with computer to computer, or Android to computer: Only iOS.
We have attempted almost everything to solve this issue - from stripping back almost all 3rd party APIs to removing most of the AngularJS code and nothing solves this mysterious (and very annoying) problem.
Versions: Angular 1.5, Opentok: 2.16.2
Please let me know if anybody came across anything like this.

How to send a link in an SMS so that the preview is loaded automatically?

I am using twilio to send SMS messages to phone numbers. What I am having problems with is making sure that once a user gets the message the preview of what is at a certain link actually loads in the message the user sees on the phone.
What is the proper way to send a link that automatically shows the preview?
EDIT:
I tried the open graph api. Apple does have a tech note on that. But, then, why does this link provided a proper preview in messages when I send this link to another phone? It works, and it does not use open graph.
https://i1.wp.com/www.asphaltandrubber.com/wp-content/uploads/2017/11/2018-Ducati-Panigale-V4-29.jpg?ssl=1
a couple of things you can try
have the link at start of the message or end of the message
the link should be properly formatted with either http:// or https://
iOS uses The Open Graph protocol to support what image to show in the link . http://ogp.me/

How do I avoid the "Open this page in 'appName'" alert from appearing in Safari for iOS?

I am creating a flow that:
1) takes the user from my iOS app to my website through Safari
2) and then navigates back into the app via javascript
However when I try and redirect the user back to my app from my site using url schemes, i get the familiar "Open this page in 'appName'" alert.
Is there a way to avoid this alert from showing up? Is there some way to whitelist my website as a source for my app to allow me to direct the user back to my app w/out any alerts?
It seems like it might be possible with Universal Links, but I am wondering if there is a simpler way to do so.
EDIT: I should have mentioned that I have the unique requirement that I need to use Safari. I am processing donations in my app, and Apple requires you to go this through Safari and not a webview. Any ideas? –
You can achieve this using webView instead of Safari,so that
control will not go out of the App.
Now the problem is how to get the click from webView, for that you can
use this approach
How to invoke Objective C method from Javascript and send back data to Javascript in iOS?
I have integrated this approach in my App so this approach will work for sure. It feels like you are in APP & some times it will diificult to differentiate between WebPage & native page

UIWebView and Analytics / Tracking Nightmare

I am building simple HTML5 presentations that will be served through an iPad app which pushes these local html5 files through UIWebView. As a developer, I am only limited to my own HTML5 code in each of these presentations. I have no access to the platform or the app these presentations reside in.
I have implemented Google Analytics. Doesn't work. I have implemented Localytics. Doesn't work. I have tried other numerous tracking platforms. They Don't work. The same code works when I upload my files to a web server and then visit it and click through. The same code does not work on the iPad. UIWebView is killing these Javascript libraries included for metrics/tracking.
Anyone ever use any metrics/tracking in a local HTML/HTML5 presentation that is served through an App using UIWebView? I am looking for somekind of solution. Your time is very much appreciated. Thank you.
Can you elaborate on "doesn't work"? I use both Google Analytics and Omniture from within a UIWebView and both work properly.
It sounds like you're tracking events, not just pageviews. That is, you're tracking when people tap on things. One thing that could be happening is the app is "trapping" those events. UIWebViews receive notifications when the apps inside them do certain things, so they can help those apps have a "native" experience. This includes things like link-handling, allowing an app to trap a Twitter intent, for instance, and send it to the actual Twitter app rather than keeping it in HTML.
It's not clear from your description whether this is the problem - but if it is, you would need to work with the app developer(s) if you wanted to keep using link tags. There's no choice - you can't stop the UIWebView from being notified, and if it does something with the event you won't get it back.
If all of this is true, try changing the elements to something other than tags. A DIV or LI, for instance, would not trigger this behavior. You'd have to do more work in your app to simulate "link-following" workflows. Something like this:
$('.tappable-item').click(function(e) {
e.preventDefault();
// Fire the analytics event
// Possibly wait 250ms or so to let the event get recorded
window.location.href = $(this).attr('data-href');
}
Google Analytics only accepts requests from the domain you configured for the campaign. What I did is create a secret page on my domain, and in the html I put an iframe that loads that page.

Resources