⚠️由于新浪服务器升级,限制目录和文件名的长度,因此更换实现方式
iOS
平台发布应用,想绕过AppStore
,最好的方式就是In-House
发布了(因为越狱用户覆盖不全,通常不考虑越狱方式)。
网上搜索In-House
的教程也不少,怎么申请企业证书,怎么对ipa
包进行大包签名我就再也不复述,文章最后附了两个连接,不了解的童鞋能够看一看。php
若是有作过In-House
部署,应该知道,须要准备一个描述应用信息的*.plist
文件上传到服务器,而且从iOS7
及之后版本,此文件必须部署在HTTPS
服务器上才能正常安装。这一步很是容易出错不能成功部署。css
签名错误或者打包方式不对。html
是由于对配置文件不了解,出错了也不知道错在哪里。ios
没有条件部署HTTPS
服务器nginx
ipa
包到http
服务器,调用一个js
方法)安装页面引入这个JS
git
<script src="http://iosinstall.sinaapp.com/plist/ios-install.js"></script>
在安装按钮的位置调用openInstallURL
方法,可使用任意HTML标签!github
<div onclick="openInstallURL({ 'title' : '我是App标题', 'ipa' : 'http://www.xxx.com/app.ipa', 'version' : '1.0', 'ident' : 'cn.xxx.xxx', 'icon' : ''});">点击安装</div>
参数说明json
参数 | 说明 | 备注 |
---|---|---|
title | 标题 | Safari弹出安装提示时提示的标题 |
ipa | 你猜 | ipa包须要你上传到本身的服务器上,而后将能够下载到这个ipa包的URL填写到这里,可使用HTTP 协议! |
version | 你再猜 | ⚠️iOS9之后,必须跟ipa包上的版本号对应,不然安装到最后会提示失败 |
ident | App惟一标识符 | 你能够在项目配置的Bundle Identifier 下看到他 |
icon | 安装加载过程当中的图标 | 若是传入空字符串,会有一个默认图标:![]() |
对HTML不熟悉的同窗能够直接用下面的代码,样式已经写好了,将其保存成*.html
文件便可服务器
<html> <head> <meta name="generator" content="HTML Tidy for Mac OS X (vers 31 October 2006 - Apple Inc. build 15.12), see www.w3.org" /> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>APP测试</title> <link rel="stylesheet" href="http://iosinstall.sinaapp.com/plist/ios-install.css"> <script src="http://iosinstall.sinaapp.com/plist/ios-install.js"></script> </head> <body> <h5 style="text-align: center; color: red; padding: 20px;">⚠️注意!如下安装包仅用于测试!<br/></h5> <install-btn onclick="openInstallURL({ 'title' : '我是标题', 'ipa' : 'http://www.xxx.com/ipa/xxxx.ipa', 'version' : '1.0', 'ident' : 'com.xxx.xxx', 'icon' : ''});">点击我安装</install-btn> </body> </html>
我曾经为了解决In-House
部署问题,也走了不少弯路,为了解决HTTPS
的问题,使用私有证书,利用Dropbox
的HTTPS服务,又或是使用Github的HTTPS服务,这些方式都是可行的,可是都有不一样程度的麻烦,因而有了今天这个帖子。app
实现逻辑:客户端根据本身的软件需求,传参到服务器,服务器动态生成*.plist
,由于iOS
会检测*.plist
的URL,不能带有参数,因此将参数用Base64
加密后加到URL路径中,服务器截取路径中的参数部分解密得到参数。因为路径变化的特殊性,须要配置好服务器的重定向。
这样,就不须要每一个新的应用都去配置一次*.plist
文件了!
我如今提供的动态*.plist
运行在新浪云稳定快速,能够放心使用!
js
实现的逻辑:收集参数,将参数加密成Base64字符串,插入到访问URL里面。
// http://iosinstall.sinaapp.com/plist/ios-install.js var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; var base64DecodeChars = new Array( -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1); // Base64编码的方法 function base64encode(str) { var out, i, len; var c1, c2, c3; len = str.length; i = 0; out = ""; while(i < len) { c1 = str.charCodeAt(i++) & 0xff; if(i == len) { out += base64EncodeChars.charAt(c1 >> 2); out += base64EncodeChars.charAt((c1 & 0x3) << 4); out += "=="; break; } c2 = str.charCodeAt(i++); if(i == len) { out += base64EncodeChars.charAt(c1 >> 2); out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4)); out += base64EncodeChars.charAt((c2 & 0xF) << 2); out += "="; break; } c3 = str.charCodeAt(i++); out += base64EncodeChars.charAt(c1 >> 2); out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4)); out += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6)); out += base64EncodeChars.charAt(c3 & 0x3F); } return out; } // 计算hash值 var I64BIT_TABLE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-'.split(''); function hash(input){ var hash = 5381; var i = input.length - 1; if(typeof input == 'string'){ for (; i > -1; i--) hash += (hash << 5) + input.charCodeAt(i); } else{ for (; i > -1; i--) hash += (hash << 5) + input[i]; } var value = hash & 0x7FFFFFFF; var retValue = ''; do{ retValue += I64BIT_TABLE[value & 0x3F]; } while(value >>= 6); return retValue; } /** Demo: var info = { 'title' : '我是标题', // app name 'ipa' : 'http://www.xxx.com/ipa/xxx.ipa', // ipa url 'version' : '1.0', 'ident' : 'cn.xxx.xxx', 'icon' : '' // icon url }; openInstallURL(info); */ function openInstallURL(info) { if (info.ident == null || info.ident.length == 0) { info.ident = 'cn.ineva.cn'; } if (info.icon == null || info.icon.length == 0) { info.icon = 'http://iosinstall.sinaapp.com/plist/ios-install.png'; } if (info.version == null || info.version.length == 0) { info.version = '1.0.0'; } var json = JSON.stringify(info) var base64String = base64encode(encodeURI(json)).replace(/\=/g, ""); var fileName = hash(base64String) var s = 128; var count = Math.ceil( base64String.length / s); var path = ""; // 由于新浪对连接文件名和目录的长度有限制,json数据,使用`/`分隔 for (var i = 0; i < count; i++) { var l = s; if (i == count - 1) { l = base64String.length - i * s; } path += "/" + base64String.substr( i * s, l); } var url = 'https://iosinstall.sinaapp.com/plist' + path + "/" + fileName + ".plist"; window.self.location = 'itms-services://?action=download-manifest&url=' + url; }
服务器PHP实现:从URL中截获参数,使用参数拼接好*.plist
文件内容,将拼接好的内容当文件返回。
<?php $pathItems = explode('/', $_SERVER["REQUEST_URI"]); if ( count($pathItems) < 4 ) { return; } $base64Data = ""; $fileName = "ios-install.plist"; for ( $i = 2; $i < count($pathItems); $i++ ) { if ( $i == count($pathItems) - 1 ) { $fileName = $pathItems[$i]; } else { $base64Data .= $pathItems[$i]; } } $jsonString = urldecode(base64_decode($base64Data)); $obj = json_decode($jsonString); $ipa = $obj->ipa; $icon = $obj->icon; $ident = $obj->ident; $version = $obj->version; $title = $obj->title; $data = '<?xml version="1.0" encoding="UTF-8"?> <plist version="1.0"> <dict> <key>items</key> <array> <dict> <key>assets</key> <array> <dict> <key>kind</key> <string>software-package</string> <key>url</key> <string>'.$ipa.'</string> </dict> <dict> <key>kind</key> <string>display-image</string> <key>needs-shine</key> <true/> <key>url</key> <string>'.$icon.'</string> </dict> </array> <key>metadata</key> <dict> <key>bundle-identifier</key> <string>'.$ident.'</string> <key>bundle-version</key> <string>'.$version.'</string> <key>kind</key> <string>software</string> <key>title</key> <string>'.$title.'</string> </dict> </dict> </array> </dict> </plist>'; $file_size = strlen($data); ob_clean(); header("Content-type:application/octet-stream"); header("Server:nginx/1.4.4"); header("Content-type:text/plain"); header("Accept-Ranges:bytes"); header("Accept-Length:".$file_size); header("Content-Disposition: attachment; filename=".$fileName); echo $data;
我开发的一个看韩国漫画的项目,使用手机上的Safari打开连接就能够安装:http://qzs21.github.io/iComic/
有兴趣的话能够看看这个项目,代码和安装包发布部署都是使用Github
(master分支下面是项目代码,gh-pages分支就是安装页面的代码): https://github.com/qzs21/iComic
很是详尽的In-House
部署教程:http://blog.csdn.net/yangxt/article/details/7998762
利用Github
的HTTPS
服务部署:http://my.oschina.net/qixiaobo025/blog/321050