mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2025-01-19 08:32:52 +08:00
feat(plugin): add sms plugin
This commit is contained in:
parent
4302abd02b
commit
aa7e04c2e7
@ -1,6 +1,4 @@
|
|||||||
import {Plugin, Cordova} from './plugin';
|
import {Plugin, Cordova} from './plugin';
|
||||||
import {isInstalled} from "./plugin";
|
|
||||||
import {pluginWarn} from "./plugin";
|
|
||||||
|
|
||||||
export interface smsOptions {
|
export interface smsOptions {
|
||||||
|
|
||||||
@ -22,15 +20,13 @@ export interface smsOptionsAndroid {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
declare var sms : any;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* Requires Cordova plugin: cordova-plugin-sms. For more info, please see the [SMS plugin docs](https://github.com/cordova-sms/cordova-sms-plugin).
|
* Requires Cordova plugin: cordova-plugin-sms. For more info, please see the [SMS plugin docs](https://github.com/cordova-sms/cordova-sms-plugin).
|
||||||
*
|
*
|
||||||
* ```
|
* ```
|
||||||
* cordova plugin add cordova-plugin-sms
|
* cordova plugin add https://github.com/cordova-sms/cordova-sms-plugin.git
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* @usage
|
* @usage
|
||||||
@ -40,25 +36,28 @@ declare var sms : any;
|
|||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
@Plugin({
|
@Plugin({
|
||||||
plugin: 'cordova-plugin-sms',
|
plugin: 'https://github.com/cordova-sms/cordova-sms-plugin.git',
|
||||||
pluginRef: 'sms'
|
pluginRef: 'sms'
|
||||||
})
|
})
|
||||||
export class SMS {
|
export class SMS {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends sms to a number
|
* Sends sms to a number
|
||||||
* @param number [number] Phone number
|
* @param number [string or array of strings] Phone number
|
||||||
* @param message [string] Message
|
* @param message [string] Message
|
||||||
* @param options [object] Options
|
* @param options [object] Options
|
||||||
* @param options.replaceLineBreaks [boolean] Set to true to replace \n by a new line. Default: false
|
* @param options.replaceLineBreaks [boolean] Set to true to replace \n by a new line. Default: false
|
||||||
* @param options.android.intent [string] Set to "INTENT" to send SMS with the native android SMS messaging. Leaving it empty will send the SMS without opening any app.
|
* @param options.android.intent [string] Set to "INTENT" to send SMS with the native android SMS messaging. Leaving it empty will send the SMS without opening any app.
|
||||||
* @returns {Promise<any>}
|
* @returns {Promise<any>}
|
||||||
*/
|
*/
|
||||||
static send(number : number, message : string, options : smsOptions) : Promise<any> {
|
@Cordova()
|
||||||
return new Promise<any>((res, rej) => {
|
static send(number : any, message : string, options? : smsOptions) : Promise<any> {
|
||||||
// TODO handle error in case plugin doesn't exist
|
// This Promise is replaced by one from the @Cordova decorator that wraps
|
||||||
sms.send(number, message, options, () => res(), (error : any) => rej(error));
|
// the plugin's callbacks. We provide a dummy one here so TypeScript
|
||||||
});
|
// knows that the correct return type is Promise, because there's no way
|
||||||
|
// for it to know the return type from a decorator.
|
||||||
|
// See https://github.com/Microsoft/TypeScript/issues/4881
|
||||||
|
return new Promise<any>((res, rej) => {});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user