iOS Create desktop shortcuts

Source: Internet
Author: User

Create desktop shortcut scenarios on iOS:

Create a shortcut to a module or page within the app on the iOS device desktop, which allows you to access the appropriate module or page directly. Currently the app has the feature of the gold one-key navigation, 360 security guard small rocket. Technical principle: In iOS development, you can use OpenURL to open a Web page and create a shortcut to the Web page by sending it to the home screen via Safari, which is the way to create a desktop shortcut for an app. Start with a lightweight httpserver inside the app, open the local page with openurl:127.0.0.1, and use the HTML redirection to point the page to a URL that contains all the information that created the desktop shortcut, followed by the data Protocol, By using Safari's Send to home screen, you can reach our requirements.

Technical difficulties:

1. Create a local httpserver. 2. Create local page and Data Association

-(ID) init{if (self = [super init]) {//start local Httpsever and Server home page Nsarray *paths = Nssearchpathfordire        Ctoriesindomains (NSDocumentDirectory, Nsuserdomainmask, YES);        NSString *documentspath = paths[0];        Self.webrootdir = [Documentspath stringbyappendingpathcomponent:@ "web"];        BOOL isdirectory = YES;        BOOL exsit = [[Nsfilemanager Defaultmanager] Fileexistsatpath:_webrootdir isdirectory:&isdirectory]; if (!exsit) {[[Nsfilemanager Defaultmanager] Createdirectoryatpath:_webrootdir Withintermediatedirectories:yes A        Ttributes:nil Error:nil];                       } self.mainpage = [NSString stringwithformat:@ "%@/web/index.html", Documentspath];                [Ddlog Addlogger:[ddttylogger sharedinstance];        _httpserver = [[Httpserver alloc] init];                [_httpserver settype:@ "_http._tcp."];                [_httpserver Setdocumentroot:_webrootdir];        Nserror *error; if ([_httpserver start:&error] {Ddloginfo (@ "Started HTTP Server on Port%hu", [_httpserver Listeningport]);        } else {Ddlogerror (@ "Error starting HTTP Server:%@", error); } [[Nsnotificationcenter defaultcenter] addobserver:self selector: @selector (applicationdidenterbackground:) Name:UI        Applicationdidenterbackgroundnotification Object:nil]; [[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (applicationwillenterforeground:) Name:    Uiapplicationwillenterforegroundnotification Object:nil]; } return self;} -(void) Applicationdidenterbackground: (uiapplication *) application{if ([[Uidevice currentdevice].systemversion    IntegerValue] >= 6.0) {sleep (1);    }else {sleep (2); } [_httpserver stop];}    -(void) Applicationwillenterforeground: (uiapplication *) application{nserror *error; if (![ _httpserver IsRunning]) {if ([_httpserver Start:&error]) {ddloginfo (@ "Started HTTP ServEr on port%hu ", [_httpserver Listeningport]);        } else {Ddlogerror (@ "Error starting HTTP Server:%@", error); }}}-(void) Createlinkwithdict: (nsdictionary *) dict Desktoplinktype: (sydesktoplinktype) linktype;    {NSString *title = [Dict objectforkey:desklinktitle];        NSString *urlscheme = [Dict objectforkey:desklinkurlscheme];    NSString *moduleid = [Dict Objectforkey:desklinkmoduletag];        NSString *imagename = [Dict objectforkey:desklinkiconname];    nsmutablestring *htmlstr = [[Nsmutablestring alloc] init];    [Htmlstr appendstring:@ "
The encoding format when negotiating URLs. 3. The local Httpserver service startup delay occurs when Safari is not started or when the app enters the background.


iOS Create desktop shortcuts

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.