YCFirstTime 1.1.3

YCFirstTime 1.1.3

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
发布最后发布2015年6月

Fabio Knoedt维护。



  • Fabio Knoedt

Dependency Status Reference Status

这是一个轻量级库,用于在应用程序生命周期或版本生命周期中仅一次执行Objective-C代码。例如,仅在应用程序第一次运行时执行代码/块。

安装

我们建议您使用CocoaPods安装此项目

Podfile

platform :ios, '6.0'
pod "YCFirstTime"

使用方法

每次应用程序安装只运行一次代码片段。

使用此选项,例如,运行一个欢迎对话框或创建一个初始数据库。

[[YCFirstTime shared] executeOnce:^{

    /// Some code that should run only ONCE per app installation.

} forKey:@"CHOOSE_AN_UNIQUE_KEY_FOR_THIS_SNIPPET"];

每次新应用程序版本运行一次代码片段

您可以利用此功能向用户展示新版本的新功能。

[[YCFirstTime shared] executeOncePerVersion:^{

    /// Some code that should run only ONCE per app version.
    /// This code will run in your version 1.0 and as well in the 1.1

} forKey:@"CHOOSE_AN_UNIQUE_KEY_FOR_THIS_SNIPPET"];

每X天运行一次代码片段

  • 用例1:每天或每两天只请求一次GPS权限(位置)。
  • 用例2:每4天只请求一次推送通知权限。
  • 用例3:每7天请求一次对应用程序进行评分。
  • 用例4:每天请求购买PRO版本。
  • 用例5:每天每小时每分钟每秒请求一次其他内容。天数参数为 CGFloat,根据需要使用。

    [[YCFirstTime shared] executeOncePerInterval:^{
    
        /// Some code that should run only ONCE per app version.
        /// This code will run in your version 1.0 and as well in the 1.1
    
    } forKey:@"CHOOSE_AN_UNIQUE_KEY_FOR_THIS_SNIPPET" withDaysInterval:2.0f];
    

第一次运行代码片段,然后从第二次开始运行另一个代码片段。

这对于需要第一次突出某些元素但从此之后希望执行另一个代码非常有用。

[[YCFirstTime shared] executeOnce:^{

    /// Some code that should run only ONCE per app installation.

} executeAfterFirstTime:^{

    /// Another piece of code to run from the SECOND time on.

} forKey:@"CHOOSE_AN_UNIQUE_KEY_FOR_THIS_SNIPPET"];

最后,您还可以将上述功能与版本检查器一起使用。

[[YCFirstTime shared] executeOncePerVersion:^{

    /// Some code that should run only ONCE per app installation.

} executeAfterFirstTime:^{

    /// Another piece of code to run from the SECOND time on.

} forKey:@"CHOOSE_AN_UNIQUE_KEY_FOR_THIS_SNIPPET"];

重置所有执行

如果您想删除所有以前的执行并从零开始,可以调用

[[YCFirstTime shared] reset];

支持

在iOS6+上运行正常,需要ARC。

贡献者