我實現了下面提到的代碼,以編程方式在iPhone中安裝Profile。還安裝了本地服務器,如RoutingHTTPServer。iPhone上的配置文件安裝編程式
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中打開空白頁面?嘗試了很多東西,但沒有運氣。請幫助我。
我想直接在配置文件安裝頁面上重定向。
你能解決這個問題嗎? –
@OmkarJadhav Nopp – Gati