├── .gitignore ├── www └── ModusEchoSwift.js ├── plugin.xml ├── README.md ├── LICENSE └── src └── ios └── ModusEchoSwift.swift /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.bak 3 | *.log 4 | *.tmp 5 | -------------------------------------------------------------------------------- /www/ModusEchoSwift.js: -------------------------------------------------------------------------------- 1 | var exec = require('cordova/exec'); 2 | 3 | exports.echo = function(arg0, success, error) { 4 | exec(success, error, 'ModusEchoSwift', 'echo', [arg0]); 5 | }; 6 | 7 | exports.echojs = function(arg0, success, error) { 8 | if (arg0 && typeof(arg0) === 'string' && arg0.length > 0) { 9 | success(arg0); 10 | } else { 11 | error('Empty message!'); 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | ModusEchoSwift 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Cordova Swift 3 Plugin Example 2 | 3 | Example Cordova plugin for iOS to support blog post. The native part of the plugin is written in Swift rather than Objective-C. This has been updated to use Swift 3 / XCode 8.2 / Cordova 6.4. 4 | 5 | A simple Cordova plugin based on the [ModusEcho plugin](https://github.com/ModusCreateOrg/cordova-plugin-example) example, which in turn was based on the echo plugin example from the [Cordova documentation](https://cordova.apache.org/docs/en/latest/guide/hybrid/plugins/index.html). 6 | 7 | * `echo` method: Extends that example to display a native dialog on iOS that auto dismisses after a short time. 8 | * `echojs` method: Basic demo showing that plugins can also be used to organize and distribute useful JavaScript, and don't need native implementations necessarily. 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Modus Create 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/ios/ModusEchoSwift.swift: -------------------------------------------------------------------------------- 1 | @objc(ModusEchoSwift) class ModusEchoSwift : CDVPlugin { 2 | @objc(echo:) 3 | func echo(command: CDVInvokedUrlCommand) { 4 | var pluginResult = CDVPluginResult( 5 | status: CDVCommandStatus_ERROR 6 | ) 7 | 8 | let msg = command.arguments[0] as? String ?? "" 9 | 10 | if msg.characters.count > 0 { 11 | let toastController: UIAlertController = 12 | UIAlertController( 13 | title: "", 14 | message: msg, 15 | preferredStyle: .alert 16 | ) 17 | 18 | self.viewController?.present( 19 | toastController, 20 | animated: true, 21 | completion: nil 22 | ) 23 | 24 | DispatchQueue.main.asyncAfter(deadline: .now() + 3) { 25 | toastController.dismiss( 26 | animated: true, 27 | completion: nil 28 | ) 29 | } 30 | 31 | pluginResult = CDVPluginResult( 32 | status: CDVCommandStatus_OK, 33 | messageAs: msg 34 | ) 35 | } 36 | 37 | self.commandDelegate!.send( 38 | pluginResult, 39 | callbackId: command.callbackId 40 | ) 41 | } 42 | } --------------------------------------------------------------------------------