问题描述
我试图在 safari 中打开一个移动配置文件 (mobileconfig) 来安装它,但没有任何效果.我使用 URL Scheme:
I'm trying to open a mobile configuration file (mobileconfig) in safari to install it but nothing work.I use URL Scheme:
NSURL *finalURL = [NSURL URLWithString:[NSString stringWithFormat:@"myAppURLScheme://%@",fileName]];
BOOL canOpen = [[UIApplication sharedApplication] openURL:finalURL];
if (canOpen) NSLog(@"can open");
else NSLog(@"can't open");
log --> 可以打开
我尝试将所有路径(文件在 Documents
文件夹中)设置为文件而不是文件名,什么都没有.我该怎么做.?
and i try to set all the path(the file is in the Documents
folder) to the file instead fileName, nothing.how can I do it. ?
Edit1:这个应用执行相同(打开 safari 安装配置)
Edit1: this application do the same(open safari to install configuration)
Edit2:我认为我必须搜索将文件(任何)发送到 safari 的方式,safari 会知道如何处理它.
Edit2: I think that i have to search the way to send file(any) to safari, and safari will know what to do with it.
推荐答案
- 授权后台任务
.h 文件:
UIBackgroundTaskIdentifier bgTask;
.m 文件:在 applicationDidEnterBackground
中添加一个新的后台任务:
.m file :In applicationDidEnterBackground
add a new background task :
bgTask = [application beginBackgroundTaskWithExpirationHandler: ^{
dispatch_async(dispatch_get_main_queue(), ^{
[application endBackgroundTask:self->bgTask];
self->bgTask = UIBackgroundTaskInvalid;
});
}];
将 CocoaHTTPServer 添加到您的项目
运行服务器并打开 .mobileconfig 文件:
Run the server and open the .mobileconfig file :
RoutingHTTPServer *httpServer = [[RoutingHTTPServer alloc] init];
[httpServer setType:@"_http._tcp."];
[httpServer setPort:12345];
[httpServer setDefaultHeader:@"Content-Type" value:@"application/x-apple-aspen-config"];
[httpServer setDocumentRoot:[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]];
if([httpServer start:nil])
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://localhost:12345/myprofile.mobileconfig"]];
}
这篇关于在 safari ios 中打开保存在应用程序中的 .mobileconfig 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!