iOS - Harpy版本更新工具兼容版本第三方庫

 

Harpy(兼容版)

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

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

提醒用戶你的應用有新的可用版本,而且及時的跳轉到App Store進行更新。

關於

Harpy 將用戶手機上已安裝的iOS app版本與當前App Store最新可用版本進行檢查對比。若是有新的可用版本時,使用彈窗及時提醒用戶最新版本信息,並然用戶選擇是否須要進一步操做。swift

Harry是基於[http://www.semver.org](Semantic Versioning)版本號系統標準執行。app

  • Semantic Versioning是一個三位數的版本號系統(例如:1.0.0)
  • Harry一樣支持2位數的版本號(例如:1.0)
  • Harpy同時支持4位數的版本號(例如:1.0.0.0)

Swift 支持

當前兼容版本(iOS5-9)暫時不支持swiftthis

特色

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

屏幕截圖

    • **左圖:**強制用戶更新app
    • **中圖:**提供可選項是否前往更新
    • **右圖:**提供跳過當前版本更新的選項
    • 這些樣式所有能夠經過HarpyAletType枚舉進行控制,詳見Harpy.h      

 

  

 

安裝

手動安裝(正在準備CocoaPods)

將‘Harpy’文件夾拖入到你的項目中,並選擇'copy if needed',包括 Harpy.h 和 Harpy.m 文件spa

配置

  1. import Harpy.h 導入到 AppDelefate 類中 或者 Pre-Complier Header(.pch)文件中
  2. 在你的Appdelegate中設置appID(必要),設置你的alertType(可選)
  3. 在你的Appdelegate中調用checkVersion方法,三個檢測方法調用位置分別位於Appdelegate的啓動的代理方法中,能夠自行選擇使用
    • 在 application:didFinishLaunchingWithOptions: 中調用 checkVersion
    • 在 applicationDidBecomeActive: 中調用 checkVersionDaily
    • 在 applicationDidBecomeActive: 中調用 checkVersionWeekly .

 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    // 啓用Harpy以前確保你的window可用
    [self.window makeKeyAndVisible];

    // 爲你的應用設置app id
    [[Harpy sharedInstance] setAppID:@"<#app_id#>"];

    // 設置 UIAlertController 將要基於哪一個控制器顯示 (適配iOS8+)
    [[Harpy sharedInstance] setPresentingViewController:_window.rootViewController];

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

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

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

     /* (可選)若是你的應用只在某些國家或地區可用,你必須使用兩個字符的country code來設置應用的可用區域 */
    [[Harpy sharedInstance] setCountryCode:@"<#country_code#>"];

    /* (可選) 強制指定應用顯示語言, 請使用 Harpy.h 中定義的 HarpyLanguage 進行設置。*/
    [[Harpy sharedInstance] setForceLanguageLocalization:<#HarpyLanguageConstant#>];

    // 執行版本檢測
    [[Harpy sharedInstance] checkVersion];
}

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

    /*
        執行天天檢測你的app是否須要更新版本,須要在`applicationDidBecomeActive:`執行最合適
        由於這對於的你的應用進如後臺很長時間後很是有用。
        
        同時,也會在應用第一次啓動時執行版本檢測
     */
    [[Harpy sharedInstance] checkVersionDaily];

    /*
        執行每週檢測你的app新版本。同理須要將此代碼放置在`applicationDidBecomeActive:`中執行。

        同時,也會在應用第一次啓動時執行版本檢測
     */
    [[Harpy sharedInstance] checkVersionWeekly];

}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    /*
     執行app新版本檢測,放在此是爲了讓用戶從App Sore跳轉回來並從新從後臺進入你的
     app,而且沒有在從App Store中跳轉回來以前更新他們app的時候調用
     
     注意:只有當你使用*HarpyAlertTypeForce*樣式彈框類型是才使用這種方法

    而且會在你第一次啓動應用時檢測。
     */
    [[Harpy sharedInstance] checkVersion];
}

 

 

項目上線遇到的問題:代理

下午提交的審覈,當晚2點就過審了,而後次日發現並無更新彈框提示....

解決:code

/**
             Checks to see when the latest version of the app was released.
             If the release date is greater-than-or-equal-to `_showAlertAfterCurrentVersionHasBeenReleasedForDays`,
             the user will prompted to update their app (if the version is newer - checked later on in this method).

查看應用程序的最新版本什麼時候發佈。若是發佈日期大於或等於「_showalertaftercurrentversionhasbeenreleaseddays(默認是1天)」,

用戶將提示更新他們的應用程序(若是版本更新—稍後在此方法中檢查)。
*/ NSString *releaseDateString = [[results valueForKey:@"currentVersionReleaseDate"] objectAtIndex:0]; if (releaseDateString == nil) { return; } else { NSInteger daysSinceRelease = [weakSelf daysSinceDateString:releaseDateString]; if (!(daysSinceRelease >= weakSelf.showAlertAfterCurrentVersionHasBeenReleasedForDays)) { NSString *message = [NSString stringWithFormat:@"Your app has been released for %ld days, but Siren cannot prompt the user until %lu days have passed.", (long)daysSinceRelease, (unsigned long)weakSelf.showAlertAfterCurrentVersionHasBeenReleasedForDays]; [self printDebugMessage:message]; return; } }

daysSinceRelease如今是爲0,因此纔會沒有彈框提示,等一天就能夠看到更新彈框了
相關文章
相關標籤/搜索