0

Using my Native iOS app to setup an MDM device takes the user out of the App to load Safari to initiate the MDM Configuration Profile Installation and then returns to Safari.

What I would like to do, is return back to the Application.

I know this can be done with RoutingHTTPServer as documented here but I can't seem to get a MDM Configuration Profile Post request to work with it.

Any help, much appreciated.

Community
  • 1
  • 1

1 Answers1

0

Using the code in the other post from @xaphod, I got it working as below but it's still not very good.

Basically I need Safari to load the profile, the user installs it the profile then clicks Done and when Safari re-opens it will direct the user back to the app.

I don't think it can be done, maybe the best workaround is hosting a webpage to do the redirection back to the app.

start server and setup routes

self.firstTime = true;

self.httpServer = [[RoutingHTTPServer alloc] init];
[self.httpServer setPort:8000];

[self.httpServer handleMethod:@"GET" withPath:@"/start" target:self selector:@selector(handleMobileconfigRootRequest:withResponse:)];
[self.httpServer handleMethod:@"GET" withPath:@"/load" target:self selector:@selector(handleMobileconfigLoadRequest:withResponse:)];

[self.httpServer start:NULL];

then to begin,

[[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"http://localhost:8000/start/"]];[/code]

which will load Safari with a JS timer

- (void)handleMobileconfigRootRequest:(RouteRequest *)request withResponse:(RouteResponse *)response
{
    [response respondWithString:@"<HTML><HEAD><title>Profile Install</title>\
     </HEAD><script> \
     function load() { window.location.href='http://localhost:8000/load/';} \
     var int=self.setTimeout(function(){load()},600); \
     </script><BODY></BODY></HTML>"];
}

first timer loads the profile in Safari, then second re-direct to the app

- (void)handleMobileconfigLoadRequest:(RouteRequest *)request withResponse:(RouteResponse *)response
{
    if (self.firstTime)
    {
        self.firstTime = FALSE;
        NSData *mobileConfigFile = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://mobileconfigfileUrl"]];

        [response setHeader:@"Content-Type" value:@"application/x-apple-aspen-config"];
        [response respondWithData:mobileConfigFile];
    }
    else
    {
        [response setStatusCode:302];
        [response setHeader:@"Location" value:@"CustomAppUrl://"];
    }
}