浅谈iOS企业内部APP分发

3,632 阅读2分钟

开发好一个APP之后,除了上线AppStore下载之后,我们经常希望有种其他的方式能让用户直接下载,而不需要等待审核。这时候就需要用到企业内部APP分发了。

分发流程

iOS 和 iPadOS 支持以无线方式安装自定的企业内部 App,而无需使用 Mac 或 App Store。它的流程大概如下。

  1. 先准备一个ipa包和一个清单文件。ipa包的格式必须为.ipa,并且使用企业内部预置描述文件进行构建。
  2. 清单文件是一个xml文件(iOS项目里经常用到的.plist文件),可以用Xcode生成。内容如下:
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <!-- array of downloads. -->
  <key>items</key>
  <array>
   <dict>
    <!-- an array of assets to download -->
     <key>assets</key>
      <array>
       <!-- software-package: the ipa to install. -->
        <dict>
         <!-- 必填项。 the asset kind. -->
          <key>kind</key>
          <string>software-package</string>
          <!-- 如果 App 文件太大,并且想要在执行错误检验(TCP 通信通常会执行该检验)的基础上确保下载的完整性,可以使用 MD5 键。 -->
          <!-- optional. md5 every n bytes. will restart a chunk if md5 fails. -->
          <key>md5-size</key>
          <integer>10485760</integer>
          <!-- optional. array of md5 hashes for each "md5-size" sized chunk. -->
          <key>md5s</key>
          <array>
            <string>41fa64bb7a7cae5a46bfb45821ac8bba</string>
            <string>51fa64bb7a7cae5a46bfb45821ac8bba</string>
          </array>
          <!-- 必填项。App (.ipa) 文件的完全限定 HTTPS URL,经验证,这里可以支持http -->
          <key>url</key>
          <string>https://www.example.com/apps/foo.ipa</string>
        </dict>
        <!-- 57 x 57 像素的 PNG 图像,在下载和安装过程中显示。指定图像的完全限定 URL。经验证非必填项,但是官方说是必填项,而且有的话下载安装过程体验好些,所以最好有。 -->
        <dict>
         <key>kind</key>
         <string>display-image</string>
         <!-- optional. indicates if icon needs shine effect applied. -->
         <key>needs-shine</key>
         <true/>
         <key>url</key>
         <string>https://www.example.com/image.57x57.png</string>
        </dict>
        <!-- 512 x 512 像素的 PNG 图像,表示 App Store 中相应的 App。经验证非必填项,但是官方说是必填项,酌情处理就好。 -->
        <dict>
         <key>kind</key>
         <string>full-size-image</string>
         <!-- optional. one md5 hash for the entire file. -->
         <key>md5</key>
         <string>61fa64bb7a7cae5a46bfb45821ac8bba</string>
         <key>needs-shine</key>
         <true/>
         <key>url</key><string>https://www.example.com/image.512x512.jpg</string>
        </dict>
      </array>
<key>metadata</key>
      <dict>
       <!-- 必填项。App 的包标识符,与 Xcode 项目中指定的完全一样 -->
       <key>bundle-identifier</key>
       <string>com.example.fooapp</string>
       <!-- 必填项。App 的包版本。跟下载包保持一致 -->
       <key>bundle-version</key>
       <string>1.0</string>
       <!-- required. the download kind. -->
       <key>kind</key>
       <string>software</string>
       <!-- optional. displayed during download; typically company name -->
       <key>subtitle</key>
       <string>Apple</string>
       <!-- 必填项。下载和安装过程中显示的 App 的名称 -->
       <key>title</key>
       <string>Example Corporate App</string>
      </dict>
    </dict>
  </array>
</dict>
</plist>
  1. 把ipa包上传服务器,得到一个ipa包的下载链接。官方建议是https,经验证,这里可以支持http。这个下载链接只能用来下载ipa包,不能自动安装。
  2. 把第二步清单文件中的https://www.example.com/apps/foo.ipa替换成第三步中获取到的下载链接。
  3. 把清单文件上传服务器,获取一个清单文件的下载链接。这里必须是https链接。类似于这样(我这是把清单文件放到了码云上,公司用的话最好是放在自己的服务器上。manifest是清单文件名):https://gitee.com/KFAaron/file_library/raw/master/manifest.plist
  4. 拿到第五步的链接,按照itms-services://协议合成一个最终的下载安装安装的连接:itms-services://?action=download-manifest&url=https://gitee.com/KFAaron/file_library/raw/master/manifest.plist。用Safari打开这个链接,就可以直接下载安装了。也可以把这个链接生成一个二维码,别人扫这个二维码就可以安装了。当然,下载安装的设备一定得确保它的网络是正常的。

验证

在iOS10.3以后,安装299刀企业证书打的包,第一次点击APP的时候,会提示信任证书。只要确保没问题,去设置-通用-设备管理里选择相应的描述文件信任即可。

然后就可以开心的使用了。

参考