|
| 1 | +import {Plugin, Cordova} from './plugin'; |
| 2 | +import {isInstalled} from "./plugin"; |
| 3 | +import {pluginWarn} from "./plugin"; |
| 4 | + |
| 5 | +export interface smsOptions { |
| 6 | + |
| 7 | + /** |
| 8 | + * Set to true to replace \n by a new line. Default: false |
| 9 | + */ |
| 10 | + replaceLineBreaks : boolean, |
| 11 | + |
| 12 | + android : smsOptionsAndroid |
| 13 | + |
| 14 | +} |
| 15 | + |
| 16 | +export interface smsOptionsAndroid { |
| 17 | + |
| 18 | + /** |
| 19 | + * Set to "INTENT" to send SMS with the native android SMS messaging. Leaving it empty will send the SMS without opening any app. |
| 20 | + */ |
| 21 | + intent : string |
| 22 | + |
| 23 | +} |
| 24 | + |
| 25 | +declare var sms : any; |
| 26 | + |
| 27 | +/** |
| 28 | + * |
| 29 | + * |
| 30 | + * Requires Cordova plugin: cordova-plugin-sms. For more info, please see the [SMS plugin docs](https://github.com/cordova-sms/cordova-sms-plugin). |
| 31 | + * |
| 32 | + * ``` |
| 33 | + * cordova plugin add cordova-plugin-sms |
| 34 | + * ``` |
| 35 | + * |
| 36 | + * @usage |
| 37 | + * ```js |
| 38 | + * |
| 39 | + * |
| 40 | + * ``` |
| 41 | + */ |
| 42 | +@Plugin({ |
| 43 | + plugin: 'cordova-plugin-sms', |
| 44 | + pluginRef: 'sms' |
| 45 | +}) |
| 46 | +export class SMS { |
| 47 | + |
| 48 | + /** |
| 49 | + * Sends sms to a number |
| 50 | + * @param number [number] Phone number |
| 51 | + * @param message [string] Message |
| 52 | + * @param options [object] Options |
| 53 | + * @param options.replaceLineBreaks [boolean] Set to true to replace \n by a new line. Default: false |
| 54 | + * @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. |
| 55 | + * @returns {Promise<any>} |
| 56 | + */ |
| 57 | + static send(number : number, message : string, options : smsOptions) : Promise<any> { |
| 58 | + return new Promise<any>((res, rej) => { |
| 59 | + // TODO handle error in case plugin doesn't exist |
| 60 | + sms.send(number, message, options, () => res(), (error : any) => rej(error)); |
| 61 | + }); |
| 62 | + } |
| 63 | + |
| 64 | +} |
0 commit comments