保存在Safari浏览器iOS应用程序打开文件.mobileconfig(Open .mobilec

2019-07-19 18:56发布

我想在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夹)的文件,而不是文件名,什么都没有。 我该怎么做。 ?

EDIT1:这个应用程序做同样的(打开Safari安装配置)

EDIT2:我认为我必须寻找到发送文件(任何)Safari浏览器的方式,Safari就会知道该怎么做。

Answer 1:

  1. 授权后台任务

.h文件中:

UIBackgroundTaskIdentifier bgTask;

.m文件:在applicationDidEnterBackground添加一个新的后台任务:

bgTask = [application beginBackgroundTaskWithExpirationHandler: ^{
        dispatch_async(dispatch_get_main_queue(), ^{
            [application endBackgroundTask:self->bgTask];
            self->bgTask = UIBackgroundTaskInvalid;
        });
    }];
  1. 添加CocoaHTTPServer到项目

  2. 运行服务器,并打开.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"]]; } 


Answer 2:

移动配置文件是您的应用程序的沙盒里面。 Safari浏览器不能访问它。 返回值[UIApplication openURL]仅表示如果有一个理解该URL方案的应用。 因为如果你要发送该URL给自己,假设你添加myAppURLSchemeURI处理程序到你的Info.plist文件在我看来。



Answer 3:

我认为你可以使用数据URI来编码和发射mobileconfig。 (我没有iOS设备在这里,所以我无法测试正确now_

您可以使用http://dopiaza.org/tools/datauri/index.php编码您的个人资料(不要忘了添加MIME类型:应用程序/ x-苹果白杨-配置)

然后,你可以打开:

[[UIApplication sharedApplication] openURL:dataURLGenerated];


Answer 4:

很没有运气要么但我张贴此无论如何,如果别人可以使用这些信息。 我试图通过打开字符串data: ,而不是通过由移动Safari浏览器支持的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");

为了测试,你可以在前面加上http://之前data:那么它至少会在Safari中打开,你可以删除前缀来试试吧。 也许一些JavaScript注入去除前缀将工作; 我不知道。



文章来源: Open .mobileconfig file saved in application in safari ios