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,因此才会没有弹框提示,等一天就能够看到更新弹框了
相关文章
相关标签/搜索