Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
627 views
in Technique[技术] by (71.8m points)

iphone - 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. 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 --> can open

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: this application do the same(open safari to install configuration)

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
  1. Authorize a background task

.h file :

UIBackgroundTaskIdentifier bgTask;

.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;
        });
    }];
  1. Add CocoaHTTPServer to your project

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...