我试图在safari中打开一个移动配置文件(mobileconfig)来安装它,但没有成功。我使用URL方案:
NSURL *finalURL = [NSURL URLWithString:[NSString stringWithFormat:@"myAppURLScheme://%@",fileName]];
BOOL canOpen = [[UIApplication sharedApplication] openURL:finalURL];
if (canOpen) NSLog(@"can open");
else NSLog(@"can't open");
日志-->can open
我尝试将所有路径(文件在Documents
文件夹中)设置为文件,而不是fileName,什么都没有。我该怎么做?
第1版:此应用程序执行相同操作(打开safari安装配置)
Edit2:我想我必须搜索将文件(任何)发送到safari的方法,safari就会知道该怎么处理它。
- 授权后台任务
.h文件:
UIBackgroundTaskIdentifier bgTask;
.m文件:在applicationDidEnterBackground
中添加一个新的后台任务:
bgTask = [application beginBackgroundTaskWithExpirationHandler: ^{
dispatch_async(dispatch_get_main_queue(), ^{
[application endBackgroundTask:self->bgTask];
self->bgTask = UIBackgroundTaskInvalid;
});
}];
将CocoaHTTPServer添加到您的项目
运行服务器并打开.mobileconfig文件:
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无法访问它。[UIApplication openURL]
的返回值仅指示是否有应用程序了解url方案。在我看来,假设您将myAppURLScheme作为uri处理程序添加到info.plist文件中,就好像您正在将该url发送给自己。
我认为您可以使用数据URI进行编码并启动mobileconfig。(我这里没有IOS设备,所以我现在无法测试_
您可以使用http://dopiaza.org/tools/datauri/index.php编码您的配置文件(不要忘记添加mime类型:application/x-apple-aspen-config)
然后你可以打开:
[[UIApplication sharedApplication] openURL:dataURLGenerated];
也很不走运,但如果其他人可以使用这些信息,我还是会发布这篇文章。我试着通过移动Safari支持的data:
url打开字符串,但openURL:
不支持——很遗憾。
NSString *urlHeader = @"data:application/x-apple-aspen-config;charset=utf-8,";
NSString *mobileConf = @"<?xmlversion="1.0"encoding="UTF-8"standalone="yes"?>"
"<!DOCTYPEplistPUBLIC"-//Apple//DTDPLIST1.0//EN""http://www.apple.com/DTDs/PropertyList-1.0.dtd">"
"<plistversion="1.0"><dict><key>PayloadUUID</key><string>A0670934-C558-42E1-9E80-9B8E079E9AB2</string><key>PayloadDisplayName</key><string>EnableTethering</string><key>PayloadDescription</key><string>EnablesTethering</string><key>PayloadOrganization</key><string>de.iphone-notes</string><key>PayloadVersion</key><integer>1</integer><key>PayloadIdentifier</key><string>de.iphone-notes.etisalat</string><key>PayloadType</key><string>Configuration</string><key>PayloadContent</key><array><dict><key>PayloadUUID</key><string>C1A41907-0CD9-4DC9-BAF1-A04A73B7E296</string><key>PayloadDisplayName</key><string>AdvancedSettings</string><key>PayloadDescription</key><string>ProvidescustomizationofcarrierAccessPointName.</string><key>PayloadOrganization</key><string>de.sendowski</string><key>PayloadVersion</key><integer>1</integer><key>PayloadIdentifier</key><string>de.iphone-notes.etisalat.apn</string><key>PayloadContent</key><array><dict><key>DefaultsDomainName</key><string>com.apple.managedCarrier</string><key>DefaultsData</key><dict><key>apns</key><array><dict><key>apn</key><string>Etisalat.ae</string><key>username</key><string></string><key>password</key><string></string><key>type-mask</key><integer>-2</integer></dict></array></dict></dict></array><key>PayloadType</key><string>com.apple.apn.managed</string></dict></array></dict></plist>";
mobileConf = [mobileConf stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSURL *finalURL = [NSURL URLWithString:[urlHeader stringByAppendingString:mobileConf]];
BOOL canOpen = [[UIApplication sharedApplication] openURL:finalURL];
if (canOpen) NSLog(@"can open");
else NSLog(@"can't open");
为了测试,你可以在data:
之前预写http://
,然后它至少会在Safari中打开,你可以删除前缀来尝试。也许一些javascript注入来删除前缀会起作用;我不知道。