Configuration profile installation on iPhone Programmatically
Asked Answered
F

1

2

I implemented code mentioned in below link to install Profile in iPhone programmatically. and also Installed a local server like RoutingHTTPServer.

https://mcmap.net/q/267996/-installing-a-configuration-profile-on-iphone-programmatically

Below is the code from the above link,

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.

    _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:@"/your.mobileconfig"];
    _mobileconfigData = [NSData dataWithContentsOfFile:path];

    [_httpServer start:NULL];

    return YES;
}

- (void)handleMobileconfigRootRequest:(RouteRequest *)request withResponse:(RouteResponse *)response {
    NSLog(@"handleMobileconfigRootRequest");
    [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 ) {
        NSLog(@"handleMobileconfigLoadRequest, first time");
        _firstTime = FALSE;

        [response setHeader:@"Content-Type" value:@"application/x-apple-aspen-config"];
        [response respondWithData:_mobileconfigData];
    } else {
        NSLog(@"handleMobileconfigLoadRequest, NOT first time");
        [response setStatusCode:302]; // or 301
        [response setHeader:@"Location" value:@"yourapp://custom/scheme"];
    }
}

... and here is the code to call into this from the app (ie viewcontroller):

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

Basically here one local server set up is there. I am quite near to get things to be done. My problem is, when I launch the application, first it open up the blank page in safari and then when I come back to application, it redirects me to profile installation page. Any idea why this is happening? Deadly stuck here. Why initially it is opening blank page in safari?

I want to redirect directly on profile installation page.

Flacon answered 11/4, 2017 at 4:37 Comment(6)
Were you able to solve this ?Zia
@OmkarJadhav NoppFlacon
@Gati have you found any solution?Pleiad
@Chetankasundra Unfortunately no!Flacon
@Gati Have you try with web-page? Open the web-page in safari from mobile and click on the download button to install the profile.Pleiad
@Chetankasundra I don't remember exactly right now. It's been so long.Flacon
V
0

It is opening a blank page in safari because you are telling it to. That's in your code: <BODY></BODY>, a blank page. Put stuff in between those tags if it shouldn't be blank.

Use the debugger. Do you ever get to this line?

NSLog(@"handleMobileconfigLoadRequest, NOT first time");

Vole answered 28/7, 2017 at 18:20 Comment(1)
This will not work for me! I use the same code that you have mentioned. I check in IOS 11.0. Please help me if you found any solution.Pleiad

© 2022 - 2024 — McMap. All rights reserved.