Question: I have built a Cordova alarm clock app that has a timer. Everything works good except that I now want to inform the user when the clock is up with a visual and audio alarm.

I have used the following plugin for local notifications: <https://github.com/katzer/cordova-plugin-local-notifications>

This seems to work good except that it doesn't seem to work when the phone screen is off.

Any ideas of a better way of doing this. I probably want something like AlarmManager in Android but so far I haven't found a Cordova plugin for it.

Answer: 
According to [n13's solution](https://stackoverflow.com/a/33461778/1151665), I made a swift3 version.

Hopes it could help some people like me.

```
import Foundation
import UIKit
import ObjectiveC

var ActionBlockKey: UInt8 = 0

// a type for our action block closure
typealias BlockButtonActionBlock = (_ sender: UIButton) -> Void

class ActionBlockWrapper : NSObject {
    var block : BlockButtonActionBlock
    init(block: @escaping BlockButtonActionBlock) {
        self.block = block
    }
}

extension UIButton {
    func block_setAction(block: @escaping BlockButtonActionBlock, for control: UIControlEvents) {
        objc_setAssociatedObject(self, &ActionBlockKey, ActionBlockWrapper(block: block), objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
        self.addTarget(self, action: #selector(UIButton.block_handleAction), for: .touchUpInside)
    }

    func block_handleAction(sender: UIButton, for control:UIControlEvents) {

        let wrapper = objc_getAssociatedObject(self, &ActionBlockKey) as! ActionBlockWrapper
        wrapper.block(sender)
    }
}

```
UIButton inherits from UIControl, which handles the receiving of input and forwarding to the selection. According to the docs, the action is "A selector identifying an action message. It cannot be NULL." And a Selector is strictly a pointer to a method. 

I would think that given the emphases Swift seems to be placing on Closures, this would be possible, but this doesnt seem to be the case.