【发布时间】:2015-02-13 00:23:18
【问题描述】:
我正在使用它来安装 mobileconfig 文件。
https://github.com/mattstevens/RoutingHTTPServer
Installing a configuration profile on iPhone - programmatically
在应用程序委托中,我写了这个。它来自应用程序,我将安装 mobileconfig 文件,它将进入 safari。之后,它将进入设置和安装。然后,它将返回 safari,然后从那里返回应用程序。但是,如果我打开 safari,它总是会路由到我的应用程序并且不会停止。我只需要这样做一次。我该怎么办?
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:@"/test.mobileconfig"];
_mobileconfigData = [NSData dataWithContentsOfFile:path];
[httpServer start:NULL];
- (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.setInterval(function(){load()},400); \
</script><BODY></BODY></HTML>"];
}
- (void)handleMobileconfigLoadRequest:(RouteRequest *)request withResponse:(RouteResponse *)response {
if( _firstTime )
{
_firstTime = FALSE;
[response setHeader:@"Content-Type" value:@"application/x-apple-aspen-config"];
[response respondWithData:_mobileconfigData];
}
else
{
[response setStatusCode:302]; // or 301
[response setHeader:@"Location" value:@"Chan://"];
}
}
【问题讨论】:
标签: ios iphone http safari routes