From 6843177377608baf74894d43bb3f9bc3fc8c6211 Mon Sep 17 00:00:00 2001 From: Ibrahim Hadeed Date: Sun, 6 Mar 2016 13:23:30 -0500 Subject: [PATCH 1/3] feat(plugin): add sms --- src/plugins/push.ts | 8 +++--- src/plugins/sms.ts | 64 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 src/plugins/sms.ts diff --git a/src/plugins/push.ts b/src/plugins/push.ts index b55caa0c3..b9c2031d3 100644 --- a/src/plugins/push.ts +++ b/src/plugins/push.ts @@ -296,10 +296,10 @@ export class Push { @Cordova() static hasPermission(){ // This Promise is replaced by one from the @Cordova decorator that wraps - // 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 + // 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<{ isEnabled: boolean }>((res, rej) => {}); } } diff --git a/src/plugins/sms.ts b/src/plugins/sms.ts new file mode 100644 index 000000000..4a0bbf3e5 --- /dev/null +++ b/src/plugins/sms.ts @@ -0,0 +1,64 @@ +import {Plugin, Cordova} from './plugin'; +import {isInstalled} from "./plugin"; +import {pluginWarn} from "./plugin"; + +export interface smsOptions { + + /** + * Set to true to replace \n by a new line. Default: false + */ + replaceLineBreaks : boolean, + + android : smsOptionsAndroid + +} + +export interface smsOptionsAndroid { + + /** + * Set to "INTENT" to send SMS with the native android SMS messaging. Leaving it empty will send the SMS without opening any app. + */ + intent : string + +} + +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). + * + * ``` + * cordova plugin add cordova-plugin-sms + * ``` + * + * @usage + * ```js + * + * + * ``` + */ +@Plugin({ + plugin: 'cordova-plugin-sms', + pluginRef: 'sms' +}) +export class SMS { + + /** + * Sends sms to a number + * @param number [number] Phone number + * @param message [string] Message + * @param options [object] Options + * @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. + * @returns {Promise} + */ + static send(number : number, message : string, options : smsOptions) : Promise { + return new Promise((res, rej) => { + // TODO handle error in case plugin doesn't exist + sms.send(number, message, options, () => res(), (error : any) => rej(error)); + }); + } + +} From 4302abd02b500291a5c276c3b47df3d132d675d8 Mon Sep 17 00:00:00 2001 From: Ibrahim Hadeed Date: Sun, 6 Mar 2016 13:24:49 -0500 Subject: [PATCH 2/3] undo --- src/plugins/push.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/plugins/push.ts b/src/plugins/push.ts index b9c2031d3..b55caa0c3 100644 --- a/src/plugins/push.ts +++ b/src/plugins/push.ts @@ -296,10 +296,10 @@ export class Push { @Cordova() static hasPermission(){ // This Promise is replaced by one from the @Cordova decorator that wraps - // 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 + // 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<{ isEnabled: boolean }>((res, rej) => {}); } } From aa7e04c2e70cd360cb4ca89ffdaa428dfc5ad80d Mon Sep 17 00:00:00 2001 From: Ibrahim Hadeed Date: Sun, 6 Mar 2016 14:51:26 -0500 Subject: [PATCH 3/3] feat(plugin): add sms plugin --- src/plugins/sms.ts | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/plugins/sms.ts b/src/plugins/sms.ts index 4a0bbf3e5..be15d57da 100644 --- a/src/plugins/sms.ts +++ b/src/plugins/sms.ts @@ -1,6 +1,4 @@ import {Plugin, Cordova} from './plugin'; -import {isInstalled} from "./plugin"; -import {pluginWarn} from "./plugin"; 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). * * ``` - * cordova plugin add cordova-plugin-sms + * cordova plugin add https://github.com/cordova-sms/cordova-sms-plugin.git * ``` * * @usage @@ -40,25 +36,28 @@ declare var sms : any; * ``` */ @Plugin({ - plugin: 'cordova-plugin-sms', + plugin: 'https://github.com/cordova-sms/cordova-sms-plugin.git', pluginRef: 'sms' }) export class SMS { /** * Sends sms to a number - * @param number [number] Phone number + * @param number [string or array of strings] Phone number * @param message [string] Message * @param options [object] Options * @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. * @returns {Promise} */ - static send(number : number, message : string, options : smsOptions) : Promise { - return new Promise((res, rej) => { - // TODO handle error in case plugin doesn't exist - sms.send(number, message, options, () => res(), (error : any) => rej(error)); - }); + @Cordova() + static send(number : any, message : string, options? : smsOptions) : Promise { + // This Promise is replaced by one from the @Cordova decorator that wraps + // 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((res, rej) => {}); } }