以编程方式在iPhone上安装配置文件 [英] Configuration profile installation on iPhone Programmatically

查看:114
本文介绍了以编程方式在iPhone上安装配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现了以下链接中提到的代码,以编程方式在iPhone中安装Profile.并且还安装了本地服务器,例如 RoutingHTTPServer .

I implemented code mentioned in below link to install Profile in iPhone programmatically. and also Installed a local server like RoutingHTTPServer.

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

下面是上面链接中的代码,

Below is the code from the above link,

- (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)调用此代码的代码:

... and here is the code to call into this from the app (ie viewcontroller):

[[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"http://localhost:8000/start/"]];

基本上,这里设置了一个本地服务器.我已经快要完成工作了.我的问题是,当我启动该应用程序时,它首先在野生动物园中打开空白页面,然后当我返回到应用程序时,它将我重定向到配置文件安装页面.知道为什么会这样吗?致命地卡在这里.为什么最初在Safari中打开空白页?

Basically here one local server set up is there. I am quite near to get things to be done. My problem is, when I launch the application, first it open up the blank page in safari and then when I come back to application, it redirects me to profile installation page. Any idea why this is happening? Deadly stuck here. Why initially it is opening blank page in safari?

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

I want to redirect directly on profile installation page.

推荐答案

它正在使用Safari浏览器打开空白页面,因为您正在告诉它.在您的代码中:<BODY></BODY>,空白页.如果内容不能为空,则将它们放在这些标签之间.

It is opening a blank page in safari because you are telling it to. That's in your code: <BODY></BODY>, a blank page. Put stuff in between those tags if it shouldn't be blank.

使用调试器.你去过这条线吗?

Use the debugger. Do you ever get to this line?

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

这篇关于以编程方式在iPhone上安装配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆