GithubHelp home page GithubHelp logo

zjutwhw / dladdtodesktop Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dlgenius/dladdtodesktop

0.0 1.0 0.0 8.23 MB

iOS 添加到主屏幕/ iOS Add To Desktop

Objective-C 98.52% HTML 0.22% Ruby 0.01% Swift 0.39% C 0.27% Shell 0.60%

dladdtodesktop's Introduction

##20160511更新内容, 增加了判断用户是否安装有目标APP的能力,如用户手机装有目标APP,点击桌面快捷图标,会直接跳转到应用,如用户未安装目标APP则会跳转到目标APP的下载页。

  • (void)addToDesktopWithDataURISchemeImage:(NSString *)dataURISchemeImage title:(NSString *)title urlScheme:(NSString *)urlScheme;

方法增加appDownloadUrl参数,改为:

  • (void)addToDesktopWithDataURISchemeImage:(NSString *)dataURISchemeImage title:(NSString *)title urlScheme:(NSString *)urlScheme appDownloadUrl:(NSString *)appDownloadUrl;

DLAddToDesktop

iOS 添加快捷方式到主屏幕/ iOS Add To Desktop ##基本实现**

利用Safari自带的添加到主屏幕功能,有两种实现方案,

实现方案一:

调用Safari访问外部页面,将外部页面作为快捷页面添加到桌面。
优点:实现简单,工作量少,页面灵活可随时更改。
缺点:无网状态下,无法生成快捷方式。

实现方案二:

通过应用内部启动httpServer,调用safari访问localhost,同时,在主页通过跳转到新的Data URI页面。
优点:不需要服务器,没网也能完成操作。
缺点:依赖的类库较多,而且实现较麻烦。

##功能封装及技术实现 方案一比较简单,就不再多说了。 本文主要针对方案二,其中用到的一些知识包括HTML、cocoaHttpServer、Data URI Scheme等,关于Data URI Scheme相关知识,可以参考我的另一篇文章 http://www.jianshu.com/p/ea49397fcd13

封装方法

针对方案二,对功能进行了封装,仅需调用3行代码,即可实现动态添加快捷方式到桌面。

###功能封装

用到的一些类库

  • CocoaHTTPServer
  • GTMBase64

使用方式: 1.工程中导入CocoaHTTPServer、GTMBase64类库 2.将Demo中的DLAddToDesktopLib文件夹拷贝到工程中

lib.png

3.在需要添加到主页面的按钮事件中加入如下代码,一下示例代码APP的下载地址以微信的地址为例,集成到自己的APP时,需替换urlScheme与appDownloadUrl参数为自己需要的参数

 DLAddToDesktopHandler *handler = [DLAddToDesktopHandler sharedInsance];
    NSString *imageString = [[UIImage imageNamed:@"webIcon"] dataURISchemeImage];
    [handler addToDesktopWithDataURISchemeImage:imageString
                                            title:@"Donglei"
                                        urlScheme:@"DLAddToDesktop://"
                                   appDownloadUrl:@"https://appsto.re/cn/S8gTy.i"];

4.别忘记设置项目的URL Types

URL Schemes.jpg

下面是一些主要的方法,

/**
 *	@brief	创建DLCreateShortcutHandler单例
 *
 *	@return	DLCreateShortcutHandler单例
 */

+(DLCreateShortcutHandler *)sharedInsance;

/**
 *	@brief	通过Safari添加快捷方式到桌面,如未安装应用会跳转到应用下载地址,如安装应用,会直接打开应用
 *
 *	@param 	dataURISchemeImage   data URI scheme
 *	@param 	title                快捷方式桌面名称
 *	@param 	urlScheme            ios APP的URL Schemes
 *	@param 	appDownloadUrl       应用下载地址
 *
 *	@return	void
 */
- (void)addToDesktopWithDataURISchemeImage:(NSString *)dataURISchemeImage title:(NSString *)title urlScheme:(NSString *)urlScheme appDownloadUrl:(NSString *)appDownloadUrl;


/**
 *	@brief	生成Data URL Scheme 形式的图片字符串
 *
 *	@return	Data URL Scheme 形式的图片字符串
 */
- (NSString *)dataURISchemeImage;

dladdtodesktop's People

Contributors

dlgenius avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.