Safari meta refresh not working with my iphone app - ios

I have an app that allows a user to install a configuration profile. I'm doing this by presenting a button on a view controller that when clicked, displays a very basic HTML page (using Cocoa HTTP Server) that has an iframe which will open the .mobileconfig file and allow the user to install it. After the user installs the profile (or indeed, cancels installation) iOS automatically switches the user back to the safari app. I've setup custom URL schemes and that works perfectly.
What I'd like to do is automatically redirect the user back to the app after they've installed the profile. I thought the best way to go about this is the http-equiv="refresh" meta tag but it seems it'll only redirect the user if they complete setup in under the refresh time (if that makes sense).
For example, if I'm able to install the profile and be switched back to safari in 3 seconds - it works. If I take 5 seconds or more to install the profile I won't be redirected. It seems like the meta refresh timer is running in the background and if Safari isn't in the foreground - it won't do it.
My question is then how do I automatically redirect the user back to my app once the profile is installed regardless of how long it takes them? I've had a look at using javascript but as you can turn that off in iPhones I'd rather not use it.
Index.html
<html>
<head>
<meta http-equiv="refresh" content="4;url=myapp://">
<meta http-equiv="content-type" content="application/x-apple-aspen-config; charset=UTF-8">
<title>Profile Installer</title>
<style>
#main{
font-family: "Helvetica";
padding-top: 500px;
padding-left: 80px;
padding-right: 50px;
}
p{
font-size: 27pt;
color: #FFFFFF;
}
</style>
</head>
<body bgcolor="#74caf2">
<div id="main">
<p>Downloading configuration profile. Please wait.</p>
</div>
<iframe width="1" height="1" frameborder="0" src="settings.mobileconfig"></iframe>
</body>
</html>

This simple JS is great to add to your code, it eliminates the problems that you mentioned with the content-refresh option in html. I understand that some users do switch off the JS in the mobileSafari but in my experience and some stats we gather from app I develop, that is 0.001% of all users.
<script type="text/javascript">
function Redirect()
{
window.location="urlScheme://";
}
setTimeout('Redirect()', 2000);
</script>

Related

Convert Custom URL scheme to QR code (IOS)

My question is what can I do to convert the custom URL scheme to a QR code that can open an app.
Let's say I have a custom URL (myScheme://). It works if I type it on my phone's browser.
But if I just convert it through some online qr code generator, the qr code reader is not going to open the url in browser and just return me a plain text.
Does it mean I need to build an own QR code reader to handle it?
I think it depends on QR Code Reader apps. In my situation I have a custom URL (itms-services://?action=download-manifest&url=xxx) QR Reader for iPhone works. But some customers said: "I can't install the app. QR just opens Safari.". There are so many QR Reader apps and we don't know which one is used.
But you can use your own web-site something like this:
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width,minimum-scale=1.0, maximum-scale=1.0" />
<title>Site Name</title>
<style>#media screen and (max-device-width:480px){body{-webkit-text-size-adjust:none}}</style>
<!-- implement javascript on web page that first first tries to open the deep link
1. if user has app installed, then they would be redirected to open the app to specified screen
2. if user doesn't have app installed, then their browser wouldn't recognize the URL scheme
and app wouldn't open since it's not installed. In 1 second (1000 milliseconds) user is redirected
to download app from app store.
-->
<script>
window.onload = function() {
<!-- Deep link URL for existing users with app already installed on their device -->
window.location = 'yourapp://app.com/?screen=xxxxx';
<!-- Download URL (MAT link) for new users to download the app -->
setTimeout("window.location = 'http://hastrk.com/serve?action=click&publisher_id=1&site_id=2';", 1000);
}
</script>
</head>
<body>
<!-- button to Download App for new app users -->
<form action="http://hastrk.com/serve?action=click&publisher_id=1&site_id=2" target="_blank">
<input type="submit" value="Download" />
</form>
<!-- button to Open App to specific screen for existing app users -->
<form action="yourapp://app.com/?screen=xxxxx" target="_blank">
<input type="submit" value="Open App" />
</form>
</body>
</html>
Then you should generate QR with website url. It will open in Safari and will redirect your app. (I hope so.)

Metarefresh is failing when Youtube iOS app is installed

Why is one metarefresh to YouTube failing while another is succeeding? And why does it have anything to do with whether Youtube as an app is installed?
We have two metarefresh links that take users to videos from an iOS app.
(1) This page refers properly to Youtube whether the Youtube iOS app is on your device or not:
The invoking link is: http://ourURL/videos/ourpage.html
The receiving HTML page is this:
<!doctype html>
<html>
<head>
<meta http-equiv="Refresh" content="0; url=http://youtu.be/tJ08IHetnbU" />
</head>
<body>
</body>
</html>
(2) The referral page that breaks is designed the same way but works only if the Youtube app is NOT on your iOS device. If the Youtube app is on your device, we see "Playback error. Tap to retry." "Error loading Tap to retry"
The invoking link is: http://ourURL.com/videos/ourpage2.html
<!doctype html>
<html>
<head>
<meta http-equiv="Refresh" content="0; url=http://youtu.be/0FZbh-Cqfg4" />
</head>
<body>
</body>
</html>
The answer turned out to be a caching issue in the YouTube app.
It appears the Youtube app relies on the Safari cache. The Meta-refresh had referred to different video links before - so the new updated links failed.
Interestingly, for whatever reason, Safari is not using its cache and showed the proper video.
After going to Settings, Safari and "Clear cookies and data" - the YouTube App started showing the referral pages properly again.

SoundCloud API stream on ios / iphone

Should the stream action via SC API / Javascript SDK 2.0.0 work on iOS/Safari?
I'm finding that it doesn't with the trivial example below.
It seems like SoundManager is capable of knowing how & when to use html5. Am I mistaken?
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<h1>Sound Cloud iOS test</h1>
<script src="//connect.soundcloud.com/sdk-2.0.0.js"></script>
<script type="text/javascript">
SC.initialize({
client_id: "YOUR_CLIENT_ID"
});
SC.stream(
'/tracks/293',
function(sound) {
sound.play()
}
);
</script>
</body>
</html>
You cannot force play or download any audio/video files in Safari on iOS devices without user initiation.
In Safari on iOS (for all devices, including iPad), where the user may
be on a cellular network and be charged per data unit, preload and
autoplay are disabled. No data is loaded until the user initiates it.
This means the JavaScript play() and load() methods are also inactive
until the user initiates playback, unless the play() or load() method
is triggered by user action. In other words, a user-initiated Play
button works, but an onLoad="play()" event does not.
This plays the movie: <input type="button" value="Play" onclick="document.myMovie.play()">
This does nothing on iOS: <body onload="document.myMovie.play()">
You will need to wrap your play action into a button, so that the audio stream is opt-in rather than automatic.
Check this article in the Safari docs for reference.

How to use images instead of plain text as links for mobile safari on iOS?

I am encountering problems with using images instead of plain text as links for mobile Safari on iOS5, tested on device. I have tried three different link protocols, tel: mailto: and http: and describe the problem for each below.
<img src="images/phone.jpg" alt="" />
Does not work in iOS5, it throws an Cannot Open Page error, but works with text as link.
<img src="images/mail.jpg" alt="" />
Does work and fires up the mail app.
<img src="images/home.jpg" alt="" />
Works as expected.
However, the 'touch-and-hold' event, which pops up with normal text links works differently for images. For mailto links this is New Message/Add to Contacts/Copy/Cancel and for tel links it is Call/Add to Contacts/Copy/Cancel.
With image links, the pop-up gives the options Open/Save Image/Copy/Cancel for both the mailto and tel links, with the Open option failing for tel links "because the address is invalid".
For my website, I would like to include my email and phone details, with the ability to mail/call directly, or to add it to the contacts. I found a related and unresolved question here:
Dial a number using Phonegap in IPhone
Any help would be greatly appreciated.
Curiously, when saved to the home screen on an iOS device, and ran as a web-app, the touch-and-hold gesture results in no popup at all for the image links, whereas the text links work fine.
(To enable a website to be run as a web-app, I added the following code in the head of the page:)
<meta name="apple-mobile-web-app-capable" content="yes" />
Can anybody reproduce this behaviour using the above link, and have clues which versions of iOS may be affected? I tested it on iPodTouch iOS 5.0.1 and iPad iOS 4.3.3. Thanks.
I noticed this same problem. To work around it, I used a CSS background-image instead of an img tag:
<style type="text/css">
.tel {
width: 102px;
height: 32px;
display: inline-block;
background: url(phone.png);
}
</style>
<a class="phone" href="tel:+1-000-000-0000"><span class="tel"></span></a>
Note that I specifically leave no whitespace inside of the a tag because otherwise the iPhone shows it next to the image (it appears for me as an empty underline, but this depends on your own CSS).
I can't repro your image link failure on iOS 5.0.1. Specifically, I put the following line into a webpage on apache:
<p>This is a test of a tel link: <img src="/iPodTouch_s4.png"></p>
A touch on the graphic brings up the phone dialog, with Cancel and Call options.
Touch-and-hold on the graphic presents Open in Phone, Save Image and Copy; touching Open in Phone brings up the phone dialog, again with Cancel and Call options.
The only way I can reproduce your experience is by mistyping the protocol designator. For example, this reproduces everything you mention (note the 1 instead of lowercase L in the href):
<p>This is a test of a tel link: <img src="/iPodTouch_s4.png"></p>
Are you positive there's no mistyping or other issue with the link?

Are offline HTML5 apps possible in iOS 4.3.4?

I'm trying my hand at building an HTML5 driven offline app for my iPad 2 which has iOS 4.3.4. I followed instructions I've seen on several websites to a tee, and was even able to verify using Chrome's Developer Tools that the cache is working:
Creating Application Cache with manifest http://localhost/experiments/test.manifest
Application Cache Checking event
Application Cache Downloading event
Application Cache Progress event (0 of 2) http://localhost/experiments/offlineApp.js
Application Cache Progress event (1 of 2) http://localhost/experiments/offlineApp.css
Application Cache Progress event (2 of 2)
Application Cache Cached event
I have a home screen icon as well as a "startup screen" image in play. I can download the app to the home screen just fine, and I see the icon there. However, when I have the Wi-Fi off and I try to open the app I get the dreaded " could not be opened because it is not connected to the Internet" alert.
Does anyone know if something changed in iOS 4.3.4 (or an earlier version of the OS) that changed the requirements to get this feature of HTML5 working?
Thanks!
Edit
I tried this again outside of a "localhost" setting. This is my HTML:
<!DOCTYPE html>
<html lang="en" manifest="/experiments/cache.manifest">
<head>
<meta charset="utf-8"/>
<title>cache.manifest test</title>
<link rel="stylesheet" href="cache-manifest-test.css"/>
<link rel="apple-touch-icon" href="icon.png"/>
</head>
<body>
<h1>cache.manifest</h1>
<p>Let's see if this thing works...</p>
<script src="cache-manifest-test.js"></script>
</body>
</html>
And this is my cache.manifest file's contents:
CACHE MANIFEST
cache-manifest-test.css
cache-manifest-test.js
I see the proper results in Chrome's developer tools. I get the "Application Cache Cached event." It just doesn't work offline. I'm really stumped here...
Does anyone know of any pages that have full blown code I could just copy to my server and try?
Thanks...
The messages you posted from Chrome are when the page is served from localhost.
Check that it works on Chrome using the server rather than localhost.
If it doesn't, check that you are serving the correct type (text/cache-manifest) for an appcache on the server.
If you're serving the correct type on localhost but not on the server, that would explain the different behavior.
Also, I've read that the file must be named "cache.manifest" on the iPad. If you have named it something else, try that.

Resources