Cordova配置IOS企業版熱更新IVersion插件

IOS企業版版本應用的更新下載不同於個人版本,無需訪問應用商店進行更新。可使用插件iVersion檢查版本更新。https://github.com/nicklockwood/iVersion

更新原理

引入插件後的App,首先訪問配置的遠程version.plist文件獲取到最新的版本號和版本更新信息,然後會和本地的版本號作比較。如果本地版本號小於遠程版本號,app會彈窗提示是否更新,即訪問配置的遠程下載地址,下載安裝更新。

操作步驟

  1. 服務器放置xxx.plist文件 ex:https://xxxx.xxxx.com/IOS/xxt.plist。
  2. 服務器放置一份version.plist文件。描述的是各個版本的更新信息。
  3. Cordova使用iVersion配置遠程version.plist文件地址和App的遠程下載地址。
  4. XCode打包發佈可自動更新的ipa包,並將包放至服務器可訪問目錄

具體操作

一、準備plist文件。文件名爲:xxt.plist。放到服務器(http://xxxxx/xxt/IOS/xxt.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://xxxxx/xxt/IOS/XXX.ipa</string>
				</dict>
				<dict>
					<key>kind</key>
					<string>display-image</string>
					<key>url</key>
					<string>https://xxxxx/xxt/IOS/logo_57x57.png</string>
				</dict>
				<dict>
					<key>kind</key>
					<string>full-size-image</string>
					<key>url</key>
					<string>https://xxxxx/xxt/IOS/logo_512x512.png</string>
				</dict>
			</array>
			<key>metadata</key>
			<dict>
				<key>bundle-identifier</key>
				<string>com.xxxxx.xxx</string>
				<key>bundle-version</key>
				<string>1.0.5</string>
				<key>kind</key>
				<string>software</string>
				<key>title</key>
				<string>XXX</string>
			</dict>
		</dict>
	</array>
</dict>
</plist>

二、XCode修改app版本信息
Xcode修改app版本信息

三、準備versions.plist文件。放到http://xxx.xx.com/ios/versions.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>1.0.5</key>
    <string>優化用戶體驗</string>
</dict>
</plist>

四、客戶端引入iVersion插件。

  1. 訪問https://github.com/nicklockwood/iVersion/tree/master/iVersion,將該目錄下的文件放置到項目的classes目錄下
    如圖
  2. AppDelegate.m文件中didFinishLaunchingWithOptions方法中以下代碼
iVersion *iv = [iVersion sharedInstance];
    iv.updateURL = [NSURL URLWithString:@"itms-services://?action=download-manifest&url=https://XXX.XXXXX.com/achivements/XXX.plist"];
    iv.remoteVersionsPlistURL = @"https://XXX.XXXXX.com/achivements/versions.plist";

  1. iVersion.m中可修改彈框按鈕的文本
- (NSString *)downloadButtonLabel
{
    return _downloadButtonLabel ?: [self localizedStringForKey:iVersionDownloadButtonKey withDefault:@"現在安裝"];
}

- (NSString *)remindButtonLabel
{
    return _remindButtonLabel ?: [self localizedStringForKey:iVersionRemindButtonKey withDefault:@"稍後提醒"];
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章