Installing .mobileconfig Locally From App

Mobileconfig files are an incredibly useful way of manging devices (iOS and Mac) en masse - configuring email accounts, VPN settings and much more, however there are some other interesting (and more novel) uses.

Over two years ago I first thought about using them to configure connecting to our school WiFi, which is both password protected and uses a proxy. I wrote a simple PHP script where you enter your school account’s username and password (for proxy authentication) and it generates a profile which is then downloaded and installed. However in order to do this, you need an internet connection - something the user won’t have, so you end up in a ‘Catch 22’ situation.

Recently as I have been preparing to update the app I developed for the school over 5 years ago, it occured to me that if I could build in profile generation this would be a really nice touch. I also decided to include optional setup of your school email account (use Microsoft Enterprise) and subscription to the school calendar (.ics).

Magic! #

I had seen apps that have used this to install webclips for use as shortcuts, however most places online (including Apple’s documentation) made no reference to this being possible - in fact most posts said this was impossible or provided very confusing and contratidctory answers.

Here are a few links to related Stackoverflow posts.

http://stackoverflow.com/questions/16536494/downloading-mobileconfig-file-from-an-app

http://stackoverflow.com/questions/9669100/how-can-you-create-a-link-wrapped-into-an-app-icon

http://stackoverflow.com/questions/2338035/installing-a-configuration-profile-on-iphone-programmatically/

It Can Be Done #

The accepted answer on the last post is in fact what roughly what I used, however it took some tweaking.

The key is running a webserver in the app which Safari then loads the files from, however once Safari is opened, your app is moved to the background and the server is paused. To work around this you start a background task, which keeps the app running for around 180 seconds longer (iOS 7).

In the answer RoutingHTTPServer is used which appears to be unneccessary - I’ve used only CocoaHTTPServer.

Sample Project #

I was going to make a sample project that installed a WiFi profile, like in the app I am working on, however I felt it a bit esoteric - instead I wanted to have something you could play about with. The app creates a shortcut to calling a phone number, where you can add a name and number in the app. I created the profile with Apple Configurator, with placeholder names which are then filled in by that app using stringByReplacingOccurrencesOfString: withString:. I also couldn’t help but make an iOS 7 inspired icon.

Please download and test the app on a device!

https://github.com/jonathanlking/LocalProfile

 
73
Kudos
 
73
Kudos

Now read this

Haptic Cycle Navigation System

I started writing this article as an idea in the last summer on the train journey back from the Custard Factory in Birmingham and decided to prototype it in late August. Since then I have had little time to develop it further, and am... Continue →