I integrated a plugin into my ionic project, which includes both Java and JS code:
cordova.define("cordova-sms-plugin.Sms", function(require, exports, module) {
'use strict';
var exec = require('cordova/exec');
var sms = {};
function convertPhoneToArray(phone) {
if (typeof phone === 'string' && phone.indexOf(',') !== -1) {
phone = phone.split(',');
}
if (Object.prototype.toString.call(phone) !== '[object Array]') {
phone = [phone];
}
return phone;
}
sms.send = function(phone, message, filename, options, success, failure) {
// parsing phone numbers
phone = convertPhoneToArray(phone);
// parsing options
var replaceLineBreaks = false;
var androidIntent = '';
if (typeof options === 'string') { // ensuring backward compatibility
window.console.warn('[DEPRECATED] Passing a string as a third argument is deprecated. Please refer to the documentation to pass the right parameter: https://github.com/cordova-sms/cordova-sms-plugin.');
androidIntent = options;
}
else if (typeof options === 'object') {
replaceLineBreaks = options.replaceLineBreaks || false;
if (options.android && typeof options.android === 'object') {
androidIntent = options.android.intent;
}
}
// fire
exec(
success,
failure,
'Sms',
'send', [phone, message, filename, androidIntent, replaceLineBreaks]
);
};
sms.hasPermission = function(success, failure) {
// fire
exec(
success,
failure,
'Sms',
'has_permission', []
);
};
module.exports = sms;
});
Now, I am trying to access the sms.send(...)
function in my Typescript code.
I have attempted to import the file using various methods like :
import sms from '../../../plugins/cordova-sms-plugin/www/sms.js';
or
import * as Sms from '../../../plugins/cordova-sms-plugin/www/sms.js';
or
window['window']['sms']['send'](...)
However, none of these approaches seem to be working as Ionic cannot locate the send()
function. Can anyone offer guidance on how to resolve this issue?