在 iPhone 上安装配置文件 - 以编程方式 [英] Installing a configuration profile on iPhone - programmatically

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

问题描述

我想随我的 iPhone 应用程序一起提供配置文件,并在需要时安装它.

请注意,我们讨论的是配置文件,而不是配置文件.

首先,这样的任务是可能的.如果您将配置文件放在网页上并从 Safari 中单击它,它将被安装.如果您通过电子邮件发送配置文件并单击附件,它也会安装.在这种情况下,已安装"表示已调用安装 UI" - 但我什至无法做到这一点.

所以我的工作原理是启动配置文件安装涉及作为 URL 导航到它.我已将配置文件添加到我的应用程序包中.

A) 首先,我尝试使用 [sharedApp openURL] 将 file://URL 添加到我的包中.没有这样的运气 - 什么也没有发生.

B) 然后我将一个 HTML 页面添加到我的包中,该页面具有指向配置文件的链接,并将其加载到 UIWebView 中.点击链接没有任何作用.但是,从 Safari 中的 Web 服务器加载相同的页面效果很好 - 链接可点击,配置文件安装.我提供了一个 UIWebViewDelegate,对每个导航请求都回答 YES - 没有区别.

C) 然后我尝试从 Safari 中的包中加载相同的网页(使用 [sharedApp openURL] - 没有任何反应.我猜,Safari 看不到我的应用包中的文件.>

D) 在 Web 服务器上上传页面和配置文件是可行的,但在组织层面上很痛苦,更不用说额外的失败来源(如果没有 3G 覆盖怎么办?等.).

所以我的大问题是:**如何以编程方式安装配置文件?

小问题是:什么可以使 UIWebView 中的链接不可点击?是否可以从 Safari 中的 my 包中加载 file://URL?如果没有,iPhone 上是否有本地位置可以放置文件而 Safari 可以找到它们?

在 B) 上 问题出在我们链接到个人资料这一事实中.我将它从 .mobileconfig 重命名为 .xml(因为它实际上是 XML),更改了链接.该链接在我的 UIWebView 中有效.将其重命名 - 同样的东西.看起来 UIWebView 不愿意做应用程序范围的事情 - 因为配置文件的安装会关闭应用程序.我试着告诉它没关系 - 通过 UIWebViewDelegate - 但这并没有说服力.mailto 的相同行为:UIWebView 中的 URL.

对于 mailto: URL 的常用技术是将它们转换为 [openURL] 调用,但这对我来说不太适用,请参阅方案 A.

对于它:URL,但是,UIWebView 按预期工作...

尝试通过 [openURL] 向 Safari 提供数据 URL - 不起作用,请参见此处:iPhone 打开数据:Safari 中的网址

发现了很多关于 Safari 如何不支持 file://URL 的信息.然而,UIWebView 非常有用.此外,模拟器上的 Safari 也可以很好地打开它们.后一点是最令人沮丧的.

<小时>

我从未找到解决方案.相反,我组合了一个两位 Web 界面,用户可以在其中订购通过电子邮件发送给他们的个人资料.

解决方案

1) 安装本地服务器,如 RoutingHTTPServer

2)配置自定义标头:

[httpServer setDefaultHeader:@"Content-Type" value:@"application/x-apple-aspen-config"];

3) 为 mobileconfig 文件(Documents)配置本地根路径:

[httpServer setDocumentRoot:[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]];

4) 为了让网络服务器有时间发送文件,添加:

Appdelegate.hUIBackgroundTaskIdentifier bgTask;Appdelegate.m- (void)applicationDidEnterBackground:(UIApplication *)application {NSAssert(self->bgTask == UIBackgroundTaskInvalid, nil);bgTask = [应用程序 beginBackgroundTaskWithExpirationHandler: ^{dispatch_async(dispatch_get_main_queue(),^{[应用结束BackgroundTask:self->bgTask];self->bgTask = UIBackgroundTaskInvalid;});}];}

5) 在您的控制器中,使用存储在 Documents 中的 mobileconfig 的名称调用 safari:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"http://localhost:12345/MyProfile.mobileconfig"]];

I would like to ship a configuration profile with my iPhone application, and install it if needed.

Mind you, we're talking about a configuration profile, not a provisioning profile.

First off, such a task is possible. If you place a config profile on a Web page and click on it from Safari, it will get installed. If you e-mail a profile and click the attachment, it will install as well. "Installed" in this case means "The installation UI is invoked" - but I could not even get that far.

So I was working under the theory that initiating a profile installation involves navigating to it as a URL. I added the profile to my app bundle.

A) First, I tried [sharedApp openURL] with the file:// URL into my bundle. No such luck - nothing happens.

B) I then added an HTML page to my bundle that has a link to the profile, and loaded it into a UIWebView. Clicking on the link does nothing. Loading an identical page from a Web server in Safari, however, works fine - the link is clickable, the profile installs. I provided a UIWebViewDelegate, answering YES to every navigation request - no difference.

C) Then I tried to load the same Web page from my bundle in Safari (using [sharedApp openURL] - nothing happens. I guess, Safari cannot see files inside my app bundle.

D) Uploading the page and the profile on a Web server is doable, but a pain on the organizational level, not to mention an extra source of failures (what if no 3G coverage? etc.).

So my big question is: **how do I install a profile programmatically?

And the little questions are: what can make a link non-clickable within a UIWebView? Is it possible to load a file:// URL from my bundle in Safari? If not, is there a local location on iPhone where I can place files and Safari can find them?

EDIT on B): the problem is somehow in the fact that we're linking to a profile. I renamed it from .mobileconfig to .xml ('cause it's really XML), altered the link. And the link worked in my UIWebView. Renamed it back - same stuff. It looks as if UIWebView is reluctant to do application-wide stuff - since installation of the profile closes the app. I tried telling it that it's OK - by means of UIWebViewDelegate - but that did not convince. Same behavior for mailto: URLs within UIWebView.

For mailto: URLs the common technique is to translate them into [openURL] calls, but that doesn't quite work for my case, see scenario A.

For itms: URLs, however, UIWebView works as expected...

EDIT2: tried feeding a data URL to Safari via [openURL] - does not work, see here: iPhone Open DATA: Url In Safari

EDIT3: found a lot of info on how Safari does not support file:// URLs. UIWebView, however, very much does. Also, Safari on the simulator open them just fine. The latter bit is the most frustrating.


EDIT4: I never found a solution. Instead, I put together a two-bit Web interface where the users can order the profile e-mailed to them.

解决方案

1) Install a local server like RoutingHTTPServer

2) Configure the custom header :

[httpServer setDefaultHeader:@"Content-Type" value:@"application/x-apple-aspen-config"];

3) Configure the local root path for the mobileconfig file (Documents):

[httpServer setDocumentRoot:[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]];

4) In order to allow time for the web server to send the file, add this :

Appdelegate.h

UIBackgroundTaskIdentifier bgTask;

Appdelegate.m
- (void)applicationDidEnterBackground:(UIApplication *)application {
    NSAssert(self->bgTask == UIBackgroundTaskInvalid, nil);
    bgTask = [application beginBackgroundTaskWithExpirationHandler: ^{
        dispatch_async(dispatch_get_main_queue(), ^{
            [application endBackgroundTask:self->bgTask];
            self->bgTask = UIBackgroundTaskInvalid;
        });
    }];
}

5) In your controller, call safari with the name of the mobileconfig stored in Documents :

[[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"http://localhost:12345/MyProfile.mobileconfig"]];

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

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