Created
January 6, 2021 13:53
-
-
Save Maxim-Kolmogorov/ec92afcedbf14ae1a10ccf0cde5f1913 to your computer and use it in GitHub Desktop.
Tutorial: Cordova plugin in Swift. Part 4.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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