import Foundation
import Capacitor
import UIKit

/**
 * Please read the Capacitor iOS Plugin Development Guide
 * here: https://capacitorjs.com/docs/plugins/ios
 */
@objc(MemoryWarning)
public class MemoryWarning: CAPPlugin {
    @objc func listenForWarning(_ call: CAPPluginCall) {
        NotificationCenter.default.addObserver(forName: UIApplication.didReceiveMemoryWarningNotification, object: nil, queue: nil) { notification in
            // print("\(#function) triggered with \(notification) notification")
            self.bridge?.triggerJSEvent(eventName: "memoryWarning", target: "document")
        }
        let value = call.getString("value") ?? ""
        call.success([
            "value": value
        ])
    }
}
