Skip to content

Commit 6843177

Browse files
committed
feat(plugin): add sms
1 parent ce6adcc commit 6843177

File tree

2 files changed

+68
-4
lines changed

2 files changed

+68
-4
lines changed

src/plugins/push.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,10 +296,10 @@ export class Push {
296296
@Cordova()
297297
static hasPermission(){
298298
// This Promise is replaced by one from the @Cordova decorator that wraps
299-
// the plugin's callbacks. We provide a dummy one here so TypeScript
300-
// knows that the correct return type is Promise, because there's no way
301-
// for it to know the return type from a decorator.
302-
// See https://github.com/Microsoft/TypeScript/issues/4881
299+
// the plugin's callbacks. We provide a dummy one here so TypeScript
300+
// knows that the correct return type is Promise, because there's no way
301+
// for it to know the return type from a decorator.
302+
// See https://github.com/Microsoft/TypeScript/issues/4881
303303
return new Promise<{ isEnabled: boolean }>((res, rej) => {});
304304
}
305305
}

src/plugins/sms.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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

Comments
 (0)