为了能快速方便的调试/发布iOS程序,我们可以采用itms-services的方法来安装iOS应用。具体的方法用如下:
1. 首先你得有一个苹果开发者账号。普通的99刀的账号只能用于发布测试程序(Ad Hoc)-只允许在100台登记在开发者账号上的机器上安装。299的企业账号可以发布所谓的In House应用,安装数量不限。299的只能企业申请。需要D-U-N-S号,只有企业才可以申请到。
2. 需要在开发者界面申请AppID,Provisioning Profile, 并且上传Certificate。具体的步骤可以参考这里:http://ask.dcloud.net.cn/docs/#http://ask.dcloud.net.cn/article/152。这些都可以在Xcode中自动完成。
3. 在Xcode中生成ipa包。
4. 编辑下载页面和plist文件。下面是这两个文件的例子。
download.html
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>安装XX应用</title>
</head>
<body>
<br>
<br>
<br>
<br>
<p align=center>
<font size="8">
<a href="itms-services://?action=download-manifest&url=https://123.123.123.123/path/to/your.plist">点击这里安装</a>
</font>
</p>
</div>
</body>
</html>
your.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<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>https://123.123.123.123/path/to/YourApp.ipa</string>
</dict>
<dict>
<key>kind</key>
<string>display-image</string>
<key>needs-shine</key>
<true/>
<key>url</key>
<string>https://123.123.123.123<span style="font-family: Arial, Helvetica, sans-serif;">/path/to/your_app_logo.png</string></span>
</dict>
<dict>
<key>kind</key>
<string>full-size-image</string>
<key>needs-shine</key>
<true/>
<key>url</key>
<string>https://123.123.123.123/path/to/your_app_logo.png</string>
</dict>
</array><key>metadata</key>
<dict>
<key>bundle-identifier</key>
<string>com.yourcompany.yourapp</string>
<key>bundle-version</key>
<string>1</string>
<key>kind</key>
<string>software</string>
<key>subtitle</key>
<string>YourAppName</string>
<key>title</key>
<string>YourAppName</string>
</dict>
</dict>
</array>
</dict>
</plist>注意:bundle-identifier要跟你在开发者网页上申请的一样。从iOS7以后,plist里面的链接必须是https的。
5. 将ipa,plist和所有的资源文件都上传的到支持https的网络硬盘上。(支持https的网盘请自行放狗搜)如果你找不到支持https的网盘。那么就需要自行配制https server。
6. 在ubuntu 14.04上配制https server。
6.1. 生成证书
openssl req -new -key server.key -out server.csr -subj "/C=CN/ST=Jiangsu/L=Suzhou/O=Xemagic Co.,Ltd./OU=Development/CN=123.123.123.123"<pre name="code" class="html">sudo openssl ca -in server.csr -config /etc/ssl/openssl.cnf -policy policy_anything
将证书copy到/etc/ssl/certs。注意证书里面的CN=123.123.123.123必须与你服务器的地址一致。即,如果你的服务器使用的是www.mycompany.com的域名则CN必须是www.mycompany.com。
6.2. 修改apache的配制文件。
配制文件的位置在 /etc/apache2/sites-available/default-ssl.conf.
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /etc/ssl/certs/your.cert
SSLCertificateKeyFile /etc/ssl/private/your.key
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
BrowserMatch "MSIE [2-6]" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
</VirtualHost>
</IfModule>
6.3. 启动apache ssh模块。
使用命令:
sudo a2enmod ssl (启动apache ssl模块)
sudo a2ensite default-ssl (启动默认的ssl服务)
sudo service apache2 reload
重新加载配制文件。
6.4. 重新启动apache服务器。
sudo service apache2 restart
7. 将服务器使用的证书安装到需要测试的手机上。
将步骤6中生成的证书(注:扩展名需要是crt或者pem)copy到服务器上可以访问到的位置。从手机上访问该链接,iphone会自动提示安装证书。跟随安装证书的步骤即可安装证书。已安装的证书可以通过 “设置-》通用-》描述文件” 查看。
这里还有个链接关于如何在Ubuntu 14.04上配制https:
https://www.digitalocean.com/community/tutorials/how-to-create-a-ssl-certificate-on-apache-for-ubuntu-14-04
-----------------
这里主要想记录一下棘手的问题。
从iOS 7.0开始,itms-services只支持使用https协议安装plist文件。这样问题就来了。。。。。我在ubuntu14.04上根据手册配置的apache + openssl总是有问题。在iPhone上总是报 “无法链接192.168.100.111”的错误。将iPhone链接到电脑上,用xCode (6.0.1) ->Window->Devices 看打印出的错误信息显示:
<Warning>: Could not load download manifest with underlying error: Error Domain=NSURLErrorDomain Code=-1202 "Cannot connect to the Store" UserInfo=0x17f511a0 {NSLocalizedDescription=Cannot connect to the Store, NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, NSLocalizedFailureReason=A secure connection could not be established. Please check your Date & Time settings., NSErrorFailingURLStringKey=https://192.168.100.111/ToDoList/ToDoList.plist, NSUnderlyingError=0x17d0cde0 "The certificate for this server is invalid. You might be connecting to a server that is pretending to be “192.168.100.111” which could put your confidential information at risk.", NSURLErrorFailingURLPeerTrustErrorKey=<SecTrustRef: 0x17fc99c0>, NSErrorFailingURLKey=https://192.168.100.111/ToDoList/ToDoList.plist}偶然试了一下使用firefox打开同样的链接,firefox报
Your connection is not private ....打开错误信息下“Advanced”的选项发现错误原因是在服务器上的证书里面使用的名字(在x509的语言里叫subject)和用浏览器访问用的url不一样。由于我在生成证书的时候没有给定名字,openssl默认取了/etc/hosts里面定义的名字(具体的机制不清楚),而我访问是用的IP地址。
问题清楚了。在openssl x509的man page里面找了半天(不知道这个名字叫subject),终于发现在生成签名请求(openssl req ...)的时候可以给定subject,于是用下面的命令:
openssl req -new -key server.key -out server.csr -subj "/C=CN/ST=Jiangsu/L=Suzhou/O=Xemagic Co.,Ltd./OU=Development/CN=192.168.100.111"重新生成一边签名请求,将subject改成192.168.100.111。然后再重新签名:
sudo openssl ca -in server.csr -config /etc/ssl/openssl.cnf -policy policy_anything将签名后的证书放到/etc/ssl/certs。重新启动apache服务: sudo service apache2 restart。
再试。前面的错误没有了。变成新的错误了:
itunesstored[609] <Warning>: Could not load download manifest with underlying error: Error Domain=SSErrorDomain Code=2 "Cannot connect to iTunes Store" UserInfo=0x17d97090 {NSLocalizedDescription=Cannot connect to iTunes Store}时间不早了,这个问题留着明天解决。;)
注:以上的解决方式只是解决了用ip访问的问题,如果一台服务器需要支持多种访问方式,比如,ip,域名,主机名,那么就需要用到x509 extension里面的Subject Alternative Name。具体方法见x509v3_config的man page。
"Could not load..."问题找到了。是plist文件里面错的<! DOCTYPE ... > 打成 <! DCTYPE ...>。少了一个O!发现这个问题纯属偶然,我尝试用浏览器打开plist文件,结果浏览器报告文件错误。生命中总是充满了意外。。。。。。
本文介绍了如何使用itms-services协议在iOS设备上安装App,包括苹果开发者账号选择、证书与配置文件的创建、ipa打包、编辑下载页面和plist文件,以及在Ubuntu 14.04上配置HTTPS服务器的详细步骤。注意,从iOS 7.0开始,itms-services要求使用HTTPS,并在配置过程中遇到了SSL连接问题和 plist 文件格式错误。
2万+

被折叠的 条评论
为什么被折叠?



