iOS创建桌面快捷方式代码

iOS创建桌面快捷方式代码,第1张

概述iOS创建桌面快捷方式代码

下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。

内存溢出小编现在分享给大家,也给大家做个参考。

    - (ID)init      {          if(self = [super init]){                            //启动本地httpSever和服务器首页页面              NSArray *paths = NSSearchPathForDirectorIEsInDomains(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 attributes: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:UIApplicationDIDEnterBackgroundNotification 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",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:@"<HTML><head>"];          [HTMLStr appendString:@"<@R_419_6135@ http-equiv=\"Content-Type\" content=\"text/HTML; charset=utf-8\">"];                    NSMutableString *taragerUrl = [NSMutableString stringWithFormat:@"0;url=data:text/HTML;charset=UTF-8,<HTML><head><@R_419_6135@ content=\"yes\" name=\"apple-mobile-web-app-capable\" /><@R_419_6135@ content=\"text/HTML; charset=UTF-8\" http-equiv=\"Content-Type\" /><@R_419_6135@ name=\"vIEwport\" content=\"wIDth=device-wIDth,initial-scale=1.0,user-scalable=no\" /><Title>%@</Title></head><body bgcolor=\"#ffffff\">",Title];                    Nsstring *HTMLUrlScheme = [Nsstring stringWithFormat:@"<a href=\"%@",urlScheme];                  Nsstring *dataUrlStr = nil;         if(linkType == SyDesktoplinkType_One){                          dataUrlStr =  [Nsstring stringWithFormat:@"%@=%@&%@=%@\" ID=\"qbt\" style=\"display: none;\"></a>",desklinkModuleTag,moduleID,desklinkType,[Nsstring stringWithInt:linkType]];                        }else if (linkType == SyDesktoplinkType_Two){              //业务生成器功能                       }else if(linkType == SyDesktoplinkType_Three){                       }                    UIImage *image = [UIImage imagenamed:imagename];          NSData *imageData = UIImagePNGRepresentation(image);                    Nsstring *base6ImageStr = [imageData base64EnCoding];                    // 转码      //  dataUrlStr = [dataUrlStr stringByAddingPercentEscapesUsingEnCoding:NSUTF8StringEnCoding];                Nsstring *imageUrlStr = [Nsstring stringWithFormat:@"<span ID=\"msg\"></span></body><script>if (window.navigator.standalone == true) {    var lnk = document.getElementByID(\"qbt\");    var evt = document.createEvent('MouseEvent');    evt.initMouseEvent('click');    lnk.dispatchEvent(evt);}else{    var addobj=document.createElement(\"link\");    addobj.setAttribute('rel','apple-touch-icon-precomposed');    addobj.setAttribute('href','data:image/png;base64,%@');",base6ImageStr];                    Nsstring *lastHTMLStr = @"document.getElementsByTagname(\"head\")[0].appendChild(addobj);    document.getElementByID(\"msg\").INNERHTML='<div style=\"Font-size:12px;\">点击页面下方的 + 或 <img ID=\"i\" src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAMAAAC6V+0/AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADW/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JliFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNiAoV2luZG93cykiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6OTU1NEJDMzMwQTBFMTFFM0FDQTA4REMyNUE4RkExNkEiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6OTU1NEJDMzQwQTBFMTFFM0FDQTA4REMyNUE4RkExNkEiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0IEG1wLmlpZDo5NTU0QkMzMTBBMEUxMUUzQUNBMDhEQzI1QThGQTE2QSIgc3RSZWY6ZG9jDW1lbnRJRD0IEG1wLmRpZDo5NTU0QkMzMjBBMEUxMUUzQUNBMDhEQzI1QThGQTE2QSIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PlMy2ugAAAAbUExUReXy/yaS/4nE/67W//n8/+n0/0yl/wB//////1m3cVcAAAAJdFJOU///////////AFNPeBIAAABDSURBVHjaxNA7DgAgCAPQoiLc/8T+EgV1p0ubxwb0E+xR8SBICBcyJUnEHktW0VwOykivvSaus6kA1CD0sZ+3aQIMAJIgC+S9X9jmAAAAAElFTkSuQmCC\"> 按钮,在d出的菜单中选择[添加至主屏幕],即可将选定的功能添加到主屏幕作为快捷方式。</div>';}</script></HTML>";                    [taragerUrl appendString:HTMLUrlScheme];          [taragerUrl appendString:dataUrlStr];          Nsstring *dataUrlEncode = [taragerUrl urlUTF8Encoded];                    Nsstring *imageUrlEncode = [imageUrlStr urlUTF8Encoded];          Nsstring *lastHTMLStrEncode = [lastHTMLStr urlCFEncoded];                              [HTMLStr appendFormat:@"<@R_419_6135@ http-equiv=\"REFRESH\" content=\"%@%@%@\">",dataUrlEncode,imageUrlEncode,lastHTMLStrEncode];          [HTMLStr appendString:@"</head></HTML>"];                    NSData *data = [HTMLStr dataUsingEnCoding:NSUTF8StringEnCoding];                    [data writetofile:_mainPage atomically:YES];                    Nsstring *urlStrWithPort = [Nsstring stringWithFormat:@"http://127.0.0.1:%d",[_httpServer ListeningPort]];          [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlStrWithPort]];      }  

以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

总结

以上是内存溢出为你收集整理的iOS创建桌面快捷方式代码全部内容,希望文章能够帮你解决iOS创建桌面快捷方式代码所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1105975.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存