Reputation: 1622
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>
Upvotes: 2
Views: 4262
Reputation: 1177
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>
Upvotes: 7