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

时间:2023-03-09 18:10:24
iOS - Harpy版本更新工具兼容版本第三方库

Harpy(兼容版)

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

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

提醒用户你的应用有新的可用版本,并且及时的跳转到App Store进行更新。

关于

Harpy 将用户手机上已安装的iOS app版本与当前App Store最新可用版本进行检查对比。如果有新的可用版本时,使用弹窗及时提醒用户最新版本信息,并然用户选择是否需要进一步操作。

Harry是基于[http://www.semver.org](Semantic Versioning)版本号系统标准执行。

  • Semantic Versioning是一个三位数的版本号系统(例如:1.0.0)
  • Harry同样支持2位数的版本号(例如:1.0)
  • Harpy同时支持4位数的版本号(例如:1.0.0.0)

Swift 支持

当前兼容版本(iOS5-9)暂时不支持swift

特点

  • 支持三种类型的弹框样式 (详见 截图 & Alert Types)
  • 提供可选的代理方法 (详见 Optional Delegate section)
  • 本地化支持超过20+语言

屏幕截图

    • **左图:**强制用户更新app
    • **中图:**提供可选项是否前往更新
    • **右图:**提供跳过当前版本更新的选项
    • 这些样式全部可以通过HarpyAletType枚举进行控制,详见Harpy.h      

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

安装

手动安装(正在准备CocoaPods)

将‘Harpy’文件夹拖入到你的项目中,并选择'copy if needed',包括 Harpy.h 和 Harpy.m 文件

配置

  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点就过审了,然后第二天发现并没有更新弹框提示....

解决:

/**
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:];
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,所以才会没有弹框提示,等一天就可以看到更新弹框了