2017-04-11 69 views
2

我实现了下面提到的代码,以编程方式在iPhone中安装Profile。还安装了本地服务器,如RoutingHTTPServeriPhone上的配置文件安装编程式

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中打开空白页面?尝试了很多东西,但没有运气。请帮助我。

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

+0

你能解决这个问题吗? –

+0

@OmkarJadhav Nopp – Gati

回答

0

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

使用调试器。你有没有去过这条路?

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