在iPhone上安装配置文件

在iPhone上安装配置文件

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

问题描述

我想使用我的iPhone应用程式传送配置设定档,如有需要可以安装。



请注意,我们在谈论配置文件,而不是配置文件。



这样的任务是可能的。如果你在一个网页上放置一个配置文件,并从Safari中点击它,它会被安装。如果您通过电子邮件发送个人资料并点击附件,它也将安装。 安装在这种情况下意味着安装UI被调用 - 但我甚至不能得到这么远。



所以我是在理论下启动配置文件安装涉及作为URL导航到它。

A)首先,我尝试将[sharedApp openURL]文件:// URL添加到我的应用程序包中束。



B)然后,我将HTML页面添加到我的包含指向个人资料链接的包中,并加载它进入一个UIWebView。点击链接什么都不做。但是,从Safari中的Web服务器加载相同的页面,工作正常 - 链接可点击,配置文件安装。我提供了一个UIWebViewDelegate,对每个导航请求都回答YES,没有区别。



C)然后我尝试从我的



D)在上传的文件夹中使用[sharedApp openURL]在Web服务器上的页面和配置文件是可行的,但在组织级别上的痛苦,更不用说额外的故障源(如果没有3G覆盖等等。)



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



在UIWebView中使链接不可点击?是否可以从Safari中的 my 包装中加载文件:// URL?如果没有,在iPhone上有一个本地位置,我可以放置文件,Safari可以找到它们?



在B上编辑是在某种程度上,我们链接到一个配置文件的事实。我把它从.mobileconfig重命名为.xml(因为它真的是XML),改变了链接。和链接工作在我的UIWebView。将它重命名为相同的东西。看起来UIWebView不愿意做应用程序范围内的东西 - 因为安装配置文件关闭了应用程序。我试图告诉它,这是OK - 通过UIWebViewDelegate - 但那不能说服。对于mailto:URL在UIWebView中。



对于mailto: URL,常见的技术是将它们转换为[openURL]



对于itms:URL,UIWebView按预期工作...



EDIT2:尝试通过[openURL]向Safari发送数据网址 - 无法正常工作,请参阅:



EDIT3:发现了很多关于Safari如何不支持file:// URL的信息。 UIWebView,但是,非常多。此外,Safari在模拟器上打开他们只是罚款。后者是最令人沮丧的。






EDIT4:我从来没有找到解决方案。

解决方案

1,我们可以使用一个两位的Web界面,用户可以通过电子邮件向他们发送电子邮件。 )安装本地服务器,如


2)配置自定义标题:

  [httpServer setDefaultHeader:@Content-Typevalue:@application / x-apple-aspen-config]; 

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

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

4)为了允许Web服务器发送文件的时间, p>

  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)在控制器中,使用存储在mobileconfig中的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上安装配置文件 - 以编程方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 03:08