為Harpy(ios版本更新工具)制做兼容版本

原文鏈接 http://yangchao0033.github.io/blog/2016/01/01/wei-harpy(ban-ben-geng-xin-gong-ju-zhi-zuo-jian-rong-ban-ben-)/

本文是對已有的版本更新工具做了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
Forced Update
Forced Update

Optional Update
Optional Update

Skipped Update
Skipped Update

安裝

手動安裝(正在準備CocoaPods)

將‘Harpy’文件夾拖入到你的項目中赂毯,并選擇'copy if needed',包括 Harpy.hHarpy.m 文件

配置

  1. import Harpy.h 導(dǎo)入到 AppDelefate 類中 或者 Pre-Complier Header(.pch)文件中
  2. 在你的Appdelegate中設(shè)置appID(必要),
    設(shè)置你的alertType(可選)

appID獲取方法:

1拣宰、在iTunes中搜索到你的應(yīng)用:

Snip20160707_6.png

2党涕、點擊箭頭:
Snip20160707_5.png

3、從鏈接中截取字符串
https://itunes.apple.com/cn/app/itunes-connect/id376771144?mt=8
其中:376771144就是他的AppID

  1. 在你的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 in Harpy.h.
Forced Update
Forced Update

Optional Update
Optional Update

Skipped Update
Skipped Update

Installation Instructions

Manual Installation

Copy the 'Harpy' folder into your Xcode project. It contains the Harpy.h and Harpy.m files.

Setup

  1. Import Harpy.h into your AppDelegate or Pre-Compiler Header (.pch)
  2. In your AppDelegate, set the appID, and optionally, you can set the alertType.
  3. In your AppDelegate, call only one of the checkVersion methods, as all three perform a check on your application's first launch. Use either:
    • checkVersion in application:didFinishLaunchingWithOptions:
    • checkVersionDaily in applicationDidBecomeActive:.
    • checkVersionWeekly in applicationDidBecomeActive:.
- (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.

Created and maintained by

Arthur Ariel Sabintsev

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末忍级,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子伪朽,更是在濱河造成了極大的恐慌轴咱,老刑警劉巖,帶你破解...
    沈念sama閱讀 211,042評論 6 490
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件烈涮,死亡現(xiàn)場離奇詭異朴肺,居然都是意外死亡,警方通過查閱死者的電腦和手機坚洽,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 89,996評論 2 384
  • 文/潘曉璐 我一進店門戈稿,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人讶舰,你說我怎么就攤上這事鞍盗。” “怎么了跳昼?”我有些...
    開封第一講書人閱讀 156,674評論 0 345
  • 文/不壞的土叔 我叫張陵愕乎,是天一觀的道長养泡。 經(jīng)常有香客問我,道長,這世上最難降的妖魔是什么掀亥? 我笑而不...
    開封第一講書人閱讀 56,340評論 1 283
  • 正文 為了忘掉前任辽聊,我火速辦了婚禮,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘觅闽。我一直安慰自己,他們只是感情好涮俄,可當我...
    茶點故事閱讀 65,404評論 5 384
  • 文/花漫 我一把揭開白布蛉拙。 她就那樣靜靜地躺著,像睡著了一般禽拔。 火紅的嫁衣襯著肌膚如雪刘离。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 49,749評論 1 289
  • 那天睹栖,我揣著相機與錄音,去河邊找鬼茧痕。 笑死野来,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的踪旷。 我是一名探鬼主播曼氛,決...
    沈念sama閱讀 38,902評論 3 405
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼令野!你這毒婦竟也來了舀患?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 37,662評論 0 266
  • 序言:老撾萬榮一對情侶失蹤气破,失蹤者是張志新(化名)和其女友劉穎聊浅,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體现使,經(jīng)...
    沈念sama閱讀 44,110評論 1 303
  • 正文 獨居荒郊野嶺守林人離奇死亡低匙,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 36,451評論 2 325
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了碳锈。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片顽冶。...
    茶點故事閱讀 38,577評論 1 340
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖售碳,靈堂內(nèi)的尸體忽然破棺而出强重,到底是詐尸還是另有隱情,我是刑警寧澤贸人,帶...
    沈念sama閱讀 34,258評論 4 328
  • 正文 年R本政府宣布间景,位于F島的核電站,受9級特大地震影響灸姊,放射性物質(zhì)發(fā)生泄漏拱燃。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 39,848評論 3 312
  • 文/蒙蒙 一力惯、第九天 我趴在偏房一處隱蔽的房頂上張望碗誉。 院中可真熱鬧召嘶,春花似錦、人聲如沸哮缺。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,726評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽尝苇。三九已至铛只,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間糠溜,已是汗流浹背淳玩。 一陣腳步聲響...
    開封第一講書人閱讀 31,952評論 1 264
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留非竿,地道東北人蜕着。 一個月前我還...
    沈念sama閱讀 46,271評論 2 360
  • 正文 我出身青樓,卻偏偏與公主長得像红柱,于是被迫代替她去往敵國和親承匣。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 43,452評論 2 348

推薦閱讀更多精彩內(nèi)容