0

I am using this to install mobileconfig file.

https://github.com/mattstevens/RoutingHTTPServer
Installing a configuration profile on iPhone - programmatically

In app delegate, I write this. It is from app, I will install mobileconfig file and it will go to safari. After that, it will go to setting and install. Then, it will go back to safari and from there, it will go back to app. But, if I open safari, it always route to my application and it doesn't stop. I need to do that only one time. How shall I do?

httpServer = [[RoutingHTTPServer alloc] init];
[httpServer setPort:8000];                               // TODO: make sure this port isn't already in use
_firstTime = TRUE;
[httpServer handleMethod:@"GET" withPath:@"/start" target:self selector:@selector(handleMobileconfigRootRequest:withResponse:)];
[httpServer handleMethod:@"GET" withPath:@"/load" target:self selector:@selector(handleMobileconfigLoadRequest:withResponse:)];

NSMutableString* path = [NSMutableString stringWithString:[[NSBundle mainBundle] bundlePath]];
[path appendString:@"/test.mobileconfig"];
_mobileconfigData = [NSData dataWithContentsOfFile:path];

[httpServer start:NULL];



- (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.setInterval(function(){load()},400); \
    </script><BODY></BODY></HTML>"];
}

- (void)handleMobileconfigLoadRequest:(RouteRequest *)request withResponse:(RouteResponse *)response  {

    if( _firstTime )
    {
        _firstTime = FALSE;
        [response setHeader:@"Content-Type" value:@"application/x-apple-aspen-config"];
       [response respondWithData:_mobileconfigData];
    }

    else
   {
       [response setStatusCode:302]; // or 301
       [response setHeader:@"Location" value:@"Chan://"];
   }

}
Community
  • 1
  • 1
Khant Thu Linn
  • 5,905
  • 7
  • 52
  • 120

1 Answers1

0

Their is an error on your test.mobileconfig file, I have the same problem and I'm still looking for the origin.

I'll post the solution if I got it. Edit: As I said before, for my case, the file was not good and also the header content-type is not applied.

So, to resolve that:

1- Force header using :

[httpServer setDefaultHeader:@"Content-Type" value:@"application/x-apple-aspen-config"];

2- Use a good mobileconfig file, here is an example of a structured one: (source: link)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Inc//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>PayloadVersion</key>
    <integer>1</integer>

    <key>PayloadUUID</key>
    <string>randomUUID</string>

    <key>PayloadType</key>
    <string>Configuration</string>

    <key>PayloadIdentifier</key>
    <string>com.example.carddav</string>

    <key>Label</key>
    <string>A Carddav Profile</string>

    <key>PayloadContent</key>
    <array>
    <dict>

        <key>CardDAVAccountDescription</key>
        <string>A Carddav Description</string>

        <key>CardDAVHostName</key>
        <string>carddav.example.com</string>

        <key>CardDAVPrincipalURL</key>
        <string>/principals/userid/</string>

        <key>CardDAVUsername</key>
        <string>userId</string>

        <key>CardDAVPassword</key>
        <string>password</string>

        <key>PayloadDescription</key>
        <string>Configures CardDAV account</string>

        <key>PayloadIdentifier</key>
        <string>com.example.carddav</string>

        <key>PayloadOrganization</key>
        <string>A nice company</string>

        <key>PayloadType</key>
        <string>com.apple.carddav.account</string>

        <key>PayloadUUID</key>
        <string>randomUUID</string>

       <key>PayloadVersion</key>
       <integer>1</integer>
    </dict>
    </array>
</dict>
</plist>
ysn mhl
  • 101
  • 5