2016-03-17 79 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://"]; 
    } 
}