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

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

本文是對(duì)已有的版本更新工具做了ios6至ios7的兼容擴(kuò)展,其使用方法與原項(xiàng)目工具類似,詳細(xì)可參照下面的介紹。

中文版:

Harpy(兼容版)

git地址:https://github.com/yangchao0033/Harpy

(iOS5-9適配版本,基于ArtSabintsev/Harpy v3.4.5)

提醒用戶你的應(yīng)用有新的可用版本,并且及時(shí)的跳轉(zhuǎn)到App Store進(jìn)行更新。

關(guān)于

Harpy 將用戶手機(jī)上已安裝的iOS app版本與當(dāng)前App Store最新可用版本進(jìn)行檢查對(duì)比。如果有新的可用版本時(shí),使用彈窗及時(shí)提醒用戶最新版本信息,并然用戶選擇是否需要進(jìn)一步操作。

Harry是基于[http://www.semver.org](Semantic Versioning)版本號(hào)系統(tǒng)標(biāo)準(zhǔn)執(zhí)行。

  • Semantic Versioning是一個(gè)三位數(shù)的版本號(hào)系統(tǒng)(例如:1.0.0)
  • Harry同樣支持2位數(shù)的版本號(hào)(例如:1.0)
  • Harpy同時(shí)支持4位數(shù)的版本號(hào)(例如:1.0.0.0)

Swift 支持

當(dāng)前兼容版本(iOS5-9)暫時(shí)不支持swift

特點(diǎn)

  • [x] 支持三種類型的彈框樣式 (詳見 截圖 & Alert Types)
  • [x] 提供可選的代理方法 (詳見 Optional Delegate section)
  • [x] 本地化支持超過20+語言

屏幕截圖

  • 左圖:強(qiáng)制用戶更新app
  • 中圖:提供可選項(xiàng)是否前往更新
  • 右圖:提供跳過當(dāng)前版本更新的選項(xiàng)
  • 這些樣式全部可以通過HarpyAletType枚舉進(jìn)行控制,詳見Harpy.h
Forced Update
Forced Update

Optional Update
Optional Update

Skipped Update
Skipped Update

安裝

手動(dòng)安裝(正在準(zhǔn)備CocoaPods)

將‘Harpy’文件夾拖入到你的項(xiàng)目中,并選擇'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、點(diǎn)擊箭頭:
Snip20160707_5.png

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

  1. 在你的Appdelegate中調(diào)用checkVersion方法,三個(gè)檢測(cè)方法調(diào)用位置分別位于Appdelegate的啟動(dòng)的代理方法中,可以自行選擇使用
    • 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 將要基于哪個(gè)控制器顯示 (適配iOS8+)
    [[Harpy sharedInstance] setPresentingViewController:_window.rootViewController];

  // (可選)設(shè)置代理來追蹤用戶點(diǎn)擊事件,活著的使用自定義的界面來展示你的信息
      [[Harpy sharedInstance] setDelegate:self];
    
    // (可選) 設(shè)置alertController的tincolor(iOS8+可用)
    [[Harpy sharedInstance] setAlertControllerTintColor:@"<#alert_controller_tint_color#>"];

    // (可選) 設(shè)置你的應(yīng)用名
    [[Harpy sharedInstance] setAppName:@"<#app_name#>"];

     /* (可選)設(shè)置彈框類型 默認(rèn)為HarpyAlertTypeOption */
    [[Harpy sharedInstance] setAlertType:<#alert_type#>];

     /* (可選)如果你的應(yīng)用只在某些國家或地區(qū)可用,你必須使用兩個(gè)字符的country code來設(shè)置應(yīng)用的可用區(qū)域 */
    [[Harpy sharedInstance] setCountryCode:@"<#country_code#>"];

    /* (可選) 強(qiáng)制指定應(yīng)用顯示語言, 請(qǐng)使用 Harpy.h 中定義的 HarpyLanguage 進(jìn)行設(shè)置。*/
    [[Harpy sharedInstance] setForceLanguageLocalization:<#HarpyLanguageConstant#>];

    // 執(zhí)行版本檢測(cè)
    [[Harpy sharedInstance] checkVersion];
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{

    /*
        執(zhí)行每天檢測(cè)你的app是否需要更新版本,需要在`applicationDidBecomeActive:`執(zhí)行最合適
        因?yàn)檫@對(duì)于的你的應(yīng)用進(jìn)如后臺(tái)很長時(shí)間后非常有用。
        
        同時(shí),也會(huì)在應(yīng)用第一次啟動(dòng)時(shí)執(zhí)行版本檢測(cè)
    */
    [[Harpy sharedInstance] checkVersionDaily];

    /*
        執(zhí)行每周檢測(cè)你的app新版本。同理需要將此代碼放置在`applicationDidBecomeActive:`中執(zhí)行。

        同時(shí),也會(huì)在應(yīng)用第一次啟動(dòng)時(shí)執(zhí)行版本檢測(cè)
     */
    [[Harpy sharedInstance] checkVersionWeekly];

}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    /*
     執(zhí)行app新版本檢測(cè),放在此是為了讓用戶從App Sore跳轉(zhuǎn)回來并重新從后臺(tái)進(jìn)入你的
     app,并且沒有在從App Store中跳轉(zhuǎn)回來之前更新他們app的時(shí)候調(diào)用
     
     注意:只有當(dāng)你使用*HarpyAlertTypeForce*樣式彈框類型是才使用這種方法

    并且會(huì)在你第一次啟動(dòng)應(yīng)用時(shí)檢測(cè)。
    */
    [[Harpy sharedInstance] checkVersion];
}

至此設(shè)置全部完成!

為不同的升級(jí)類型設(shè)置彈窗樣式

如果你喜歡為不同的升級(jí)類型比如修改(revision),補(bǔ)丁(patch),輕微改動(dòng)(minor),重大修改(major)等升級(jí)類型僅僅添加下面的幾行可選代碼即可,添加位置必須在調(diào)用版本檢查的方法(checkVersion)之前

    /* 默認(rèn)情況下Harpy會(huì)設(shè)置所有的版本升級(jí)樣式為HarpyAlertTypeOption */
    [[Harpy sharedInstance] setPatchUpdateAlertType:<#alert_type#>];
    [[Harpy sharedInstance] setMinorUpdateAlertType:<#alert_type#>];
    [[Harpy sharedInstance] setMajorUpdateAlertType:<#alert_type#>];
    [[Harpy sharedInstance] setRevisionUpdateAlertType:<#alert_type#>];

可選的代理和代理方法

如果你想要個(gè)處理或者追蹤終端用戶的的行為,Harpy會(huì)為你提供四個(gè)代理方法進(jìn)行監(jiān)控

    // 用戶界面展示升級(jí)提示對(duì)話框
    - (void)harpyDidShowUpdateDialog;

    // 用戶已經(jīng)點(diǎn)擊升級(jí)按鈕并且進(jìn)入到App Sotore
    - (void)harpyUserDidLaunchAppStore;

    // 用戶已經(jīng)點(diǎn)擊跳過此次版本更新
    - (void)harpyUserDidSkipVersion;

    // 用戶已經(jīng)點(diǎn)擊取消更行對(duì)話框
    - (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,如果有可用的新版本,使用下面的代理來獲得本地化的升級(jí)信息(需要設(shè)置AlertTpye為HarpyAlertTypeNone)

- (void)harpyDidDetectNewVersionWithoutAlert:(NSString *)message;

強(qiáng)制本地化

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.

你可能想要你的升級(jí)對(duì)話框永遠(yuǎn)顯示正確的語言,而忽略iOS的語言設(shè)置(比如在指定國家發(fā)行的app)

你可以使用以下代碼實(shí)現(xiàn)強(qiáng)制本地化

[[Harpy sharedInstance] setForceLanguageLocalization<#HarpyLanguageConstant#>];

在App Store上提交的重要注意事項(xiàng)

App Store 審核人員將不會(huì)看到升級(jí)彈框

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)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容