以编程方式在 iPhone 上安装配置文件



我实现了以下链接中提到的代码,以编程方式在iPhone中安装配置文件。 并且还安装了像路由HTTPServer这样的本地服务器。

https://stackoverflow.com/a/21014275/3825016

下面是上面链接中的代码,

- (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"];
    }
}

。这是从应用程序(即视图控制器(调用它的代码:

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

基本上这里设置了一个本地服务器。我快要把事情办好了。我的问题是,当我启动应用程序时,首先它会在 safari 中打开空白页面,然后当我返回应用程序时,它会将我重定向到配置文件安装页面。知道为什么会这样吗?致命的卡在这里。为什么最初它在 safari 中打开空白页?

我想直接在配置文件安装页面上重定向。

它在 safari 中打开一个空白页,因为你告诉它这样做。这在你的代码中:<BODY></BODY>,一个空白页。如果不应该是空白,请将内容放在这些标签之间。

使用调试器。你曾经到过这条线吗?

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

最新更新