IOS App Internal build profile (iii) Safari open a profile

Source: Internet
Author: User

This is the topic of the last article, in doubt can leave a message, I try to reply.

Be clear: Safari doesn't have direct access to our app's sandbox files.

Here's a workaround: Create an HTTP server inside the app and let safari download the description file inside the server. (There may be other ways)

There are several third-party libraries in the app to build the server, and I'll use it here to list (I won't add a link to the jump, you can go to GitHub to download)

  

The method used is relatively easy: I post the code

This is. h

#import #import " RoutingHTTPServer.h " #import uibackgroundtaskidentifier bgtask;//background run ID  @interface {  }  @property (Strong, Nonatomic) UIWindow *window; readonly) Routinghttpserver *httpserver; @end

. m I added a forced change to the file format in the server to make sure Safari can open directly

#import "AppDelegate.h"@interfaceappdelegate ()- (void) StartServer;@end@implementationappdelegate-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions {//Override point for customization after application launch.[self startserver];    returnYES;}/** To start a HTTP server*/- (void) startserver{//Create Server using our custom Myhttpserver class_httpserver =[[Routinghttpserver alloc] init];
/** * * * * * * * * Add by AK * * * * * * * * * * * * * * **//*set file format to Apple.mobileconfig*/[_httpserver setdefaultheader:@"Content-type"Value@"Application/x-apple-aspen-config"]; //Tell the server to broadcast its presence via Bonjour. //This allows browsers such as Safari to automatically discover our service.[_httpserver SetType:@"_http._tcp."]; //normally there ' s no need to run we server on any specific port. //Technologies like Bonjour allow clients to dynamically discover the server's port at runtime. //However, for easy testing you may want force a certain port so can just hit the refresh button.[_httpserver Setport:8000];
NSString*documentsdirectory = [Nssearchpathfordirectoriesindomains (nsdocumentdirectory, Nsuserdomainmask, YES) Objectatindex:0]; [_httpserver Setdocumentroot:documentsdirectory]; if(_httpserver.isrunning) [_httpserver stop]; Nserror*error; if([_httpserver start:&ERROR]) {NSLog (@"Started HTTP Server on port%hu", [_httpserver Listeningport]); } Else{NSLog (@"Error starting HTTP Server:%@", error); //Probably should add an escape-but in practice never loops more than twice (bug filed on GitHubhttps://github.com/robbiehanson/CocoaHTTPServer/issues/88)[self startserver]; }}- (void) Applicationwillresignactive: (UIApplication *) Application {//Sent when the application are about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as a incoming phone call or SMS message) or when the US Er quits the application and it begins the transition to the background state. //Use the This method to the pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.}- (void) Applicationdidenterbackground: (UIApplication *) Application {//Use the method to release the shared resources, save user data, invalidate timers, and store enough application state in Formation to the restore your application to the it is terminated later. //If Your application supports background execution, this method is called instead of Applicationwillterminate:when th E user quits. if(!bgtask) {Bgtask= [Application Beginbackgroundtaskwithexpirationhandler: ^{Dispatch_async (Dispatch_get_main_queue (),^{[Application endbackgroundtask:bgtask]; Bgtask=Uibackgroundtaskinvalid; }); }]; }}- (void) Applicationwillenterforeground: (UIApplication *) Application {//Called as part of the transition from the background to the inactive state; Here you can undo many of the changes mad E on entering the background.}- (void) Applicationdidbecomeactive: (UIApplication *) Application {//Restart Any tasks this were paused (or not yet started) while the application is inactive. If the application is previously in the background, optionally refresh the user interface.}- (void) Applicationwillterminate: (UIApplication *) Application {//Called when the application are about to terminate. Save data if appropriate. See also Applicationdidenterbackground:.}

There are two points to note:

1, need to apply for background operation permissions, after all, the browser to download it

2. The path of file storage is consistent with the previous one, that is, the same as where you write

IOS App Internal build profile (iii) Safari open a profile

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.