Skip to content

Instantly share code, notes, and snippets.

@Maxim-Kolmogorov
Created January 6, 2021 13:53
Show Gist options
  • Save Maxim-Kolmogorov/ec92afcedbf14ae1a10ccf0cde5f1913 to your computer and use it in GitHub Desktop.
Save Maxim-Kolmogorov/ec92afcedbf14ae1a10ccf0cde5f1913 to your computer and use it in GitHub Desktop.
Tutorial: Cordova plugin in Swift. Part 4.
@objc(EchoTest) class EchoTest : CDVPlugin {
@objc(echo:)
func echo(command: CDVInvokedUrlCommand) {
var pluginResult = CDVPluginResult(
status: CDVCommandStatus_ERROR
)
let msg = command.arguments[0] as? String ?? ""
if msg.characters.count > 0 {
let toastController: UIAlertController =
UIAlertController(
title: "",
message: msg,
preferredStyle: .alert
)
self.viewController?.present(
toastController,
animated: true,
completion: nil
)
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
toastController.dismiss(
animated: true,
completion: nil
)
}
pluginResult = CDVPluginResult(
status: CDVCommandStatus_OK,
messageAs: msg
)
}
self.commandDelegate!.send(
pluginResult,
callbackId: command.callbackId
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment