Giter Club home page Giter Club logo

verificationcodetimermanager's Introduction

VerificationCodeTimerManager

验证码倒计时管理器

安装

将CodeTimerManager.swift文件拖入项目中

说明

项目功能,简单易用。

倒计时开始不论退出界面还是进入后台,都能继续倒计时(只要不杀死APP)。

可根据需求修改代码。

使用

在控制器中创建一个获取验证码按钮并初始化定时器管理

let codeManager: CodeTimerManager = CodeTimerManager.init(type: .login, buttonTitle: "获取验证码")

viewDidLoad中调用func start(_ phone: String?, _ button: UIButton)设置定时器管理

override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        codeManager.start("134XXXXXXXX", codeButton)
    }

deinit中调用func finish()停止并移除定时器

deinit {
        codeManager.finish()
        print("\(self)已释放")
    }

在按钮点击事件中启动定时器

@objc func buttonClick() {
        codeManager.timerStart()
    }

AppDelegate中进入前台方法中调用发送进入前台通知方法

func applicationWillEnterForeground(_ application: UIApplication) {
        // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
        CodeTimerManager.postForegroundNoti()
    }

AppDelegate中进入后台方法中调用发送进入后台通知方法

func applicationDidEnterBackground(_ application: UIApplication) {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
        CodeTimerManager.postBackgroundNoti()
    }

枚举

设置对象codeType

enum codeType {
        case login      //登录
        case pay        //支付
        case regist     //注册
        case forget     //忘记密码
    }

详细使用请参看DEMO

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.