git地址:https://github.com/yangchao0033/Harpygit
###(iOS5-9適配版本,基於ArtSabintsev/Harpy v3.4.5)github
Harpy 將用戶手機上已安裝的iOS app版本與當前App Store最新可用版本進行檢查對比。若是有新的可用版本時,使用彈窗及時提醒用戶最新版本信息,並然用戶選擇是否須要進一步操做。swift
Harry是基於[http://www.semver.org](Semantic Versioning)版本號系統標準執行。app
Semantic Versioning
是一個三位數的版本號系統(例如:1.0.0)當前兼容版本(iOS5-9)暫時不支持swiftthis
HarpyAletType
枚舉進行控制,詳見Harpy.h
將‘Harpy’文件夾拖入到你的項目中,並選擇'copy if needed',包括 Harpy.h
和 Harpy.m
文件spa
Appdelegate
中設置appID(必要),設置你的alertType(可選)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,因此纔會沒有彈框提示,等一天就能夠看到更新彈框了