繁体   English   中英

在safari ios中打开保存在应用程序中的.mobileconfig文件

[英]Open .mobileconfig file saved in application in safari ios

我正在尝试在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");

log - > can open

我尝试将所有路径(文件在Documents文件夹中)设置为文件而不是fileName,没有。 我该怎么做。

Edit1 :这个应用程序也这样做(打开safari来安装配置)

Edit2 :我认为我必须搜索发送文件(任何)到safari的方式,safari将知道如何处理它。

  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"]]; } 

移动配置文件位于应用程序的沙箱中 Safari无法访问它。 [UIApplication openURL]的返回值仅指示是否有应用程序了解该url方案 它看起来好像你正在向自己发送这个url,假设你将myAppURLScheme作为uri处理程序添加到你的info.plist文件中。

我想你可以使用数据URI来编码和启动mobileconfig。 (我这里没有IOS设备,所以我现在无法测试_

您可以使用http://dopiaza.org/tools/datauri/index.php对您的个人资料进行编码(不要忘记添加mime类型:application / x-apple-aspen-config)

然后你可以打开:

[[UIApplication sharedApplication] openURL:dataURLGenerated];

我也没有运气但是如果其他人可以使用这些信息我发布这个。 我尝试通过data: url打开字符串,这是由Mobile Safari支持的,但不是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注入删除前缀将起作用; 我不知道。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM