简体   繁体   English

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

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

I'm trying to open a mobile configuration file (mobileconfig) in safari to install it but nothing work. 我正在尝试在safari中打开一个移动配置文件(mobileconfig)来安装它,但没有任何效果。 I use URL Scheme: 我使用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 log - > can open

and i try to set all the path(the file is in the Documents folder) to the file instead fileName, nothing. 我尝试将所有路径(文件在Documents文件夹中)设置为文件而不是fileName,没有。 how can I do it. 我该怎么做。 ?

Edit1 : this application do the same(open safari to install configuration) Edit1 :这个应用程序也这样做(打开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. Edit2 :我认为我必须搜索发送文件(任何)到safari的方式,safari将知道如何处理它。

  1. Authorize a background task 授权后台任务

.h file : .h文件:

UIBackgroundTaskIdentifier bgTask;

.m file : In applicationDidEnterBackground add a new background task : .m文件:在applicationDidEnterBackground添加一个新的后台任务:

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

  2. Run the server and open the .mobileconfig file : 运行服务器并打开.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"]]; } 

The mobile config file is inside your app's sandbox . 移动配置文件位于应用程序的沙箱中 Safari doesn't have access to it. Safari无法访问它。 The return value of [UIApplication openURL] only indicates if there was an application that understands that url scheme . [UIApplication openURL]的返回值仅指示是否有应用程序了解该url方案 It looks to me as if you're sending that url to yourself, assuming that you added myAppURLScheme as a uri handler to your info.plist file. 它看起来好像你正在向自己发送这个url,假设你将myAppURLScheme作为uri处理程序添加到你的info.plist文件中。

I think you can use data URI to encode and launch mobileconfig. 我想你可以使用数据URI来编码和启动mobileconfig。 (I don't have IOS device here, so I cannot test right now_ (我这里没有IOS设备,所以我现在无法测试_

You can use http://dopiaza.org/tools/datauri/index.php to encode your profile (don't forget to add mime type: application/x-apple-aspen-config) 您可以使用http://dopiaza.org/tools/datauri/index.php对您的个人资料进行编码(不要忘记添加mime类型:application / x-apple-aspen-config)

Then you can open: 然后你可以打开:

[[UIApplication sharedApplication] openURL:dataURLGenerated];

quite had no luck either but I post this anyway if someone else can use this information. 我也没有运气但是如果其他人可以使用这些信息我发布这个。 I tried opening the string via data: url which is supported by Mobile Safari, but not by openURL: – sadly. 我尝试通过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");

For testing you can prepend http:// before data: then it will at least open in Safari and you can delete the prefix to try it. 对于测试,您可以在data:之前添加http://然后它至少会在Safari中打开,您可以删除前缀来尝试它。 Maybe some javascript injection to remove the prefix will work; 也许一些javascript注入删除前缀将起作用; I don't know. 我不知道。

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

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