本文是對已有的版本更新工具做了ios6至ios7的兼容擴展砰逻,其使用方法與原項目工具類似婉宰,詳細可參照下面的介紹。
中文版:
Harpy(兼容版)
git地址:https://github.com/yangchao0033/Harpy
(iOS5-9適配版本,基于ArtSabintsev/Harpy v3.4.5)
提醒用戶你的應(yīng)用有新的可用版本仅叫,并且及時的跳轉(zhuǎn)到App Store進行更新藕届。
關(guān)于
Harpy 將用戶手機上已安裝的iOS app版本與當前App Store最新可用版本進行檢查對比勺鸦。如果有新的可用版本時妨退,使用彈窗及時提醒用戶最新版本信息讽坏,并然用戶選擇是否需要進一步操作锭魔。
Harry是基于[http://www.semver.org](Semantic Versioning)版本號系統(tǒng)標準執(zhí)行。
-
Semantic Versioning
是一個三位數(shù)的版本號系統(tǒng)(例如:1.0.0) - Harry同樣支持2位數(shù)的版本號(例如:1.0)
- Harpy同時支持4位數(shù)的版本號(例如:1.0.0.0)
Swift 支持
當前兼容版本(iOS5-9)暫時不支持swift
特點
- [x] 支持三種類型的彈框樣式 (詳見 截圖 & Alert Types)
- [x] 提供可選的代理方法 (詳見 Optional Delegate section)
- [x] 本地化支持超過20+語言
屏幕截圖
- 左圖:強制用戶更新app
- 中圖:提供可選項是否前往更新
- 右圖:提供跳過當前版本更新的選項
- 這些樣式全部可以通過
HarpyAletType
枚舉進行控制震缭,詳見Harpy.h
安裝
手動安裝(正在準備CocoaPods)
將‘Harpy’文件夾拖入到你的項目中赂毯,并選擇'copy if needed',包括 Harpy.h
和 Harpy.m
文件
配置
- import Harpy.h 導(dǎo)入到 AppDelefate 類中 或者 Pre-Complier Header(.pch)文件中
- 在你的
Appdelegate
中設(shè)置appID(必要),
設(shè)置你的alertType(可選)
appID獲取方法:
1拣宰、在iTunes中搜索到你的應(yīng)用:
2党涕、點擊箭頭:
3、從鏈接中截取字符串
https://itunes.apple.com/cn/app/itunes-connect/id376771144?mt=8
其中:376771144
就是他的AppID
- 在你的
Appdelegate
中調(diào)用checkVersion
方法巡社,三個檢測方法調(diào)用位置分別位于Appdelegate的啟動的代理方法中膛堤,可以自行選擇使用- 在
application:didFinishLaunchingWithOptions:
中調(diào)用checkVersion
- 在
applicationDidBecomeActive:
中調(diào)用checkVersionDaily
- 在
applicationDidBecomeActive:
中調(diào)用checkVersionWeekly
.
- 在
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// 啟用Harpy之前確保你的window可用
[self.window makeKeyAndVisible];
// 為你的應(yīng)用設(shè)置app id
[[Harpy sharedInstance] setAppID:@"<#app_id#>"];
// 設(shè)置 UIAlertController 將要基于哪個控制器顯示 (適配iOS8+)
[[Harpy sharedInstance] setPresentingViewController:_window.rootViewController];
// (可選)設(shè)置代理來追蹤用戶點擊事件,活著的使用自定義的界面來展示你的信息
[[Harpy sharedInstance] setDelegate:self];
// (可選) 設(shè)置alertController的tincolor(iOS8+可用)
[[Harpy sharedInstance] setAlertControllerTintColor:@"<#alert_controller_tint_color#>"];
// (可選) 設(shè)置你的應(yīng)用名
[[Harpy sharedInstance] setAppName:@"<#app_name#>"];
/* (可選)設(shè)置彈框類型 默認為HarpyAlertTypeOption */
[[Harpy sharedInstance] setAlertType:<#alert_type#>];
/* (可選)如果你的應(yīng)用只在某些國家或地區(qū)可用晌该,你必須使用兩個字符的country code來設(shè)置應(yīng)用的可用區(qū)域 */
[[Harpy sharedInstance] setCountryCode:@"<#country_code#>"];
/* (可選) 強制指定應(yīng)用顯示語言, 請使用 Harpy.h 中定義的 HarpyLanguage 進行設(shè)置肥荔。*/
[[Harpy sharedInstance] setForceLanguageLocalization:<#HarpyLanguageConstant#>];
// 執(zhí)行版本檢測
[[Harpy sharedInstance] checkVersion];
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
/*
執(zhí)行每天檢測你的app是否需要更新版本绿渣,需要在`applicationDidBecomeActive:`執(zhí)行最合適
因為這對于的你的應(yīng)用進如后臺很長時間后非常有用。
同時燕耿,也會在應(yīng)用第一次啟動時執(zhí)行版本檢測
*/
[[Harpy sharedInstance] checkVersionDaily];
/*
執(zhí)行每周檢測你的app新版本中符。同理需要將此代碼放置在`applicationDidBecomeActive:`中執(zhí)行。
同時誉帅,也會在應(yīng)用第一次啟動時執(zhí)行版本檢測
*/
[[Harpy sharedInstance] checkVersionWeekly];
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
/*
執(zhí)行app新版本檢測淀散,放在此是為了讓用戶從App Sore跳轉(zhuǎn)回來并重新從后臺進入你的
app,并且沒有在從App Store中跳轉(zhuǎn)回來之前更新他們app的時候調(diào)用
注意:只有當你使用*HarpyAlertTypeForce*樣式彈框類型是才使用這種方法
并且會在你第一次啟動應(yīng)用時檢測蚜锨。
*/
[[Harpy sharedInstance] checkVersion];
}
至此設(shè)置全部完成档插!
為不同的升級類型設(shè)置彈窗樣式
如果你喜歡為不同的升級類型比如修改(revision),補丁(patch)亚再,輕微改動(minor)郭膛,重大修改(major)等升級類型僅僅添加下面的幾行可選代碼即可,添加位置必須在調(diào)用版本檢查的方法(checkVersion)之前
/* 默認情況下Harpy會設(shè)置所有的版本升級樣式為HarpyAlertTypeOption */
[[Harpy sharedInstance] setPatchUpdateAlertType:<#alert_type#>];
[[Harpy sharedInstance] setMinorUpdateAlertType:<#alert_type#>];
[[Harpy sharedInstance] setMajorUpdateAlertType:<#alert_type#>];
[[Harpy sharedInstance] setRevisionUpdateAlertType:<#alert_type#>];
可選的代理和代理方法
如果你想要個處理或者追蹤終端用戶的的行為氛悬,Harpy會為你提供四個代理方法進行監(jiān)控
// 用戶界面展示升級提示對話框
- (void)harpyDidShowUpdateDialog;
// 用戶已經(jīng)點擊升級按鈕并且進入到App Sotore
- (void)harpyUserDidLaunchAppStore;
// 用戶已經(jīng)點擊跳過此次版本更新
- (void)harpyUserDidSkipVersion;
// 用戶已經(jīng)點擊取消更行對話框
- (void)harpyUserDidCancel;
If you would like to use your own UI, please use the following delegate method to obtain the localized update message if a new version is available:
如果你想使用自己的UI则剃,如果有可用的新版本,使用下面的代理來獲得本地化的升級信息(需要設(shè)置AlertTpye為HarpyAlertTypeNone)
- (void)harpyDidDetectNewVersionWithoutAlert:(NSString *)message;
強制本地化
Harpy 已經(jīng)本地化了的語言包括 Arabic, Basque, 簡體中文, 繁體中文, Danish, Dutch, English, Estonian, French, German, Hebrew, Hungarian, Italian, Japanese, Korean, Latvian, Lithuanian, Malay, Polish, Portuguese (Brazil), Portuguese (Portugal), Russian, Slovenian, Swedish, Spanish, Thai, and Turkish.
你可能想要你的升級對話框永遠顯示正確的語言圆雁,而忽略iOS的語言設(shè)置(比如在指定國家發(fā)行的app)
你可以使用以下代碼實現(xiàn)強制本地化
[[Harpy sharedInstance] setForceLanguageLocalization<#HarpyLanguageConstant#>];
在App Store上提交的重要注意事項
App Store 審核人員將不會看到升級彈框
English:
Harpy(Compatible version Base On ArtSabintsev/Harpy v3.4.5)
Notify users when a new version of your app is available, and prompt them with the App Store link.
About
Harpy checks a user's currently installed version of your iOS app against the version that is currently available in the App Store. If a new version is available, an alert can be presented to the user informing them of the newer version, and giving them the option to update the application.
Harpy is built to work with the [http://www.semver.org](Semantic Versioning) system.
- Semantic Versioning is a three number versioning system (e.g., 1.0.0)
- Harpy also supports two-number versioning (e.g., 1.0)
- Harpy also supports four-number versioning (e.g., 1.0.0.0)
Swift Support
- not support yet
Features
- [x] Three types of alerts (see Screenshots & Alert Types)
- [x] Optional delegate methods (see Optional Delegate section)
- [x] Localized for 20+ languages
Screenshots
- The left picture forces the user to update the app.
- The center picture gives the user the option to update the app.
- The right picture gives the user the option to skip the current update.
- These options are controlled by the
HarpyAlertType
typede that is found inHarpy.h
.
Installation Instructions
Manual Installation
Copy the 'Harpy' folder into your Xcode project. It contains the Harpy.h and Harpy.m files.
Setup
- Import Harpy.h into your AppDelegate or Pre-Compiler Header (.pch)
- In your
AppDelegate
, set the appID, and optionally, you can set the alertType. - In your
AppDelegate
, call only one of thecheckVersion
methods, as all three perform a check on your application's first launch. Use either:-
checkVersion
inapplication:didFinishLaunchingWithOptions:
-
checkVersionDaily
inapplicationDidBecomeActive:
. -
checkVersionWeekly
inapplicationDidBecomeActive:
.
-
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Present Window before calling Harpy
[self.window makeKeyAndVisible];
// Set the App ID for your app
[[Harpy sharedInstance] setAppID:@"<#app_id#>"];
// Set the UIViewController that will present an instance of UIAlertController
[[Harpy sharedInstance] setPresentingViewController:_window.rootViewController];
// (Optional) Set the Delegate to track what a user clicked on, or to use a custom UI to present your message.
[[Harpy sharedInstance] setDelegate:self];
// (Optional) The tintColor for the alertController
[[Harpy sharedInstance] setAlertControllerTintColor:@"<#alert_controller_tint_color#>"];
// (Optional) Set the App Name for your app
[[Harpy sharedInstance] setAppName:@"<#app_name#>"];
/* (Optional) Set the Alert Type for your app
By default, Harpy is configured to use HarpyAlertTypeOption */
[[Harpy sharedInstance] setAlertType:<#alert_type#>];
/* (Optional) If your application is not available in the U.S. App Store, you must specify the two-letter
country code for the region in which your applicaiton is available. */
[[Harpy sharedInstance] setCountryCode:@"<#country_code#>"];
/* (Optional) Overrides system language to predefined language.
Please use the HarpyLanguage constants defined in Harpy.h. */
[[Harpy sharedInstance] setForceLanguageLocalization:<#HarpyLanguageConstant#>];
// Perform check for new version of your app
[[Harpy sharedInstance] checkVersion];
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
/*
Perform daily check for new version of your app
Useful if user returns to you app from background after extended period of time
Place in applicationDidBecomeActive:
Also, performs version check on first launch.
*/
[[Harpy sharedInstance] checkVersionDaily];
/*
Perform weekly check for new version of your app
Useful if you user returns to your app from background after extended period of time
Place in applicationDidBecomeActive:
Also, performs version check on first launch.
*/
[[Harpy sharedInstance] checkVersionWeekly];
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
/*
Perform check for new version of your app
Useful if user returns to you app from background after being sent tot he App Store,
but doesn't update their app before coming back to your app.
ONLY USE THIS IF YOU ARE USING *HarpyAlertTypeForce*
Also, performs version check on first launch.
*/
[[Harpy sharedInstance] checkVersion];
}
And you're all set!
Differentiated Alerts for Patch, Minor, and Major Updates
If you would like to set a different type of alert for revision, patch, minor, and/or major updates, simply add one or all of the following optional lines to your setup before calling any of the checkVersion
methods:
/* By default, Harpy is configured to use HarpyAlertTypeOption for all version updates */
[[Harpy sharedInstance] setPatchUpdateAlertType:<#alert_type#>];
[[Harpy sharedInstance] setMinorUpdateAlertType:<#alert_type#>];
[[Harpy sharedInstance] setMajorUpdateAlertType:<#alert_type#>];
[[Harpy sharedInstance] setRevisionUpdateAlertType:<#alert_type#>];
Optional Delegate and Delegate Methods
If you'd like to handle or track the end-user's behavior, four delegate methods have been made available to you:
// User presented with update dialog
- (void)harpyDidShowUpdateDialog;
// User did click on button that launched App Store.app
- (void)harpyUserDidLaunchAppStore;
// User did click on button that skips version update
- (void)harpyUserDidSkipVersion;
// User did click on button that cancels update dialog
- (void)harpyUserDidCancel;
If you would like to use your own UI, please use the following delegate method to obtain the localized update message if a new version is available:
- (void)harpyDidDetectNewVersionWithoutAlert:(NSString *)message;
Force Localization
Harpy has localizations for Arabic, Basque, Chinese (Simplified), Chinese (Traditional), Danish, Dutch, English, Estonian, French, German, Hebrew, Hungarian, Italian, Japanese, Korean, Latvian, Lithuanian, Malay, Polish, Portuguese (Brazil), Portuguese (Portugal), Russian, Slovenian, Swedish, Spanish, Thai, and Turkish.
You may want the update dialog to always appear in a certain language, ignoring iOS's language setting (e.g. apps released in a specific country).
You can enable it like this:
[[Harpy sharedInstance] setForceLanguageLocalization<#HarpyLanguageConstant#>];
Important Note on App Store Submissions
The App Store reviewer will not see the alert.