2017-04-11 3 views
2

아래 링크에 언급 된 코드를 구현하여 iPhone에 프로파일을 프로그래밍 방식으로 설치했습니다. RoutingHTTPServer과 같은 로컬 서버도 설치했습니다. 다음은 iPhone의 구성 프로파일 설치 프로그램 적으로

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

(즉의 ViewController),

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

기본적으로 하나의 로컬 서버가 설정되어 있습니다. 나는 일을 끝내기에 아주 가깝다. 내 문제는 응용 프로그램을 시작할 때 사파리에서 빈 페이지를 열면 응용 프로그램으로 돌아올 때 프로필 설치 페이지로 리디렉션된다는 것입니다. 왜 이런 일이 일어나는 지 아십니까? 여기에 치명적인 걸세. 어떤 도움을 주셔서 감사합니다. 처음에는 사파리에서 빈 페이지가 열리는 이유는 무엇입니까? 여러 가지를 시도했지만 운이 아직 없습니다. 제발 도와주세요.

프로필 설치 페이지에서 직접 리디렉션하고 싶습니다.

+0

이 문제를 해결할 수 있었습니까? –

+0

@OmkarJadhav Nopp – Gati

답변

0

당신이 말하고 있기 때문에 그것은 사파리에서 빈 페이지를 여는 중입니다. 귀하의 코드에 있습니다 : <BODY></BODY>, 빈 페이지. 빈 태그가 아닌 태그 사이에 물건을 넣으십시오.

디버거를 사용하십시오. 이 라인에 다녀 왔습니까?

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

관련 문제