2016-03-17 49 views

回答

0

使用@xphod的另一篇文章中的代码,我得到它的工作如下,但它仍然不是很好。

基本上我需要Safari加载配置文件,用户安装它的配置文件,然后点击完成,当Safari重新打开它将引导用户回到应用程序。

我不认为它可以完成,也许最好的解决方法是托管一个网页做重定向回应用程序。

启动服务器和设置路由

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]; 

然后开始,

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

将加载的Safari与JS计时器

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

第一定时器加载Safari中的配置文件,然后第二重新定向到应用

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