私はプログラムでiPhoneにプロファイルをインストールするために、以下のリンクに記載されているコードを実装しました。 RoutingHTTPServerのようなローカルサーバーをインストールしました。以下はiPhoneでの設定プロファイルのインストールprogramed
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"];
}
}
からのコードです...と、ここでアプリ(すなわちのViewController)からこのに呼び出すコードです:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"http://localhost:8000/start/"]];
基本的にここに1台のローカルサーバーが設定されています。私は物事を完了させるためにかなり近くにいます。私の問題は、私がアプリケーションを起動すると、最初にサファリの空白のページを開き、アプリケーションに戻るとプロファイルのインストールページにリダイレクトされます。なぜこれが起こっているのか?致命的にここにこだわった。どんな助けもありがとうございます。最初はなぜサファリで空白のページを開いているのですか?複数のことを試みましたが、運はまだありません。私を助けてください。
プロファイルのインストールページに直接リダイレクトします。
これを解決できましたか? –
@OmkarJadhav Nopp – Gati