Plugin for sending short messages using the device's SMS app.
npm i @byteowls/capacitor-sms
Minimum Capacitor version is 1.0.0
This example shows the common process of configuring this plugin.
Although it was taken from a Angular 6 application, it should work in other frameworks as well.
Find the init component of your app, which is in Angular app.component.ts
and register this plugin by
import {registerWebPlugin} from "@capacitor/core";
import {SmsManager} from '@byteowls/capacitor-sms';
@Component()
export class AppComponent implements OnInit {
ngOnInit() {
console.log("Register custom capacitor plugins");
registerWebPlugin(SmsManager);
// other stuff
}
}
This plugin always uses the default sms app.
Google prevented me from using SMS_SEND permission so I dropped the support here because the plugin is much easier to maintain if only one feature is supported.
for (const m of messages) {
const numbers: string[] = [];
for (const r of m.recipients) {
numbers.push(r.mobile);
}
Plugins.SmsManager.send({
numbers: numbers,
text: m.content,
}).then(() => {
// SMS app was opened
}).catch(error => {
// see error codes below
if (error.message !== "SEND_CANCELLED") {
// show toast with error message
console.log(error.message);
}
});
}
- SEND_CANCELLED ... User cancelled or closed the SMS app. (ios only)
- ERR_SEND_FAILED ... The SMS app returned that sending the message to the recipients failed. (ios only)
- ERR_SEND_UNKNOWN_STATE ... The SMS app returned a unknown state. There is nothing I can do to clarify the error. (ios only)
- ERR_PLATFORM_NOT_SUPPORTED ... Sending SMS on the web is not supported.
- ERR_NO_NUMBERS ... No recipient numbers were retrieved from options. Make sure to deliver only valid numbers, because the whole sending will fail.
- ERR_NO_TEXT ... No message text was retrieved from options.
- ERR_SERVICE_NOTFOUND ... The used device can not send SMS.
Register the plugin in com.companyname.appname.MainActivity#onCreate
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
List<Class<? extends Plugin>> additionalPlugins = new ArrayList<>();
// Additional plugins you've installed go here
// Ex: additionalPlugins.add(TotallyAwesomePlugin.class);
additionalPlugins.add(SmsManagerPlugin.class);
// Initializes the Bridge
this.init(savedInstanceState, additionalPlugins);
}
- On iOS the plugin is registered automatically by Capacitor.
- Not supported.
- Not supported.
Please do not mix more than one issue in a feature branch. Each feature/bugfix should have its own branch and its own Pull Request (PR).
- Create a issue and describe what you want to do at Issue Tracker
- Create your feature branch (
git checkout -b feature/my-feature
orgit checkout -b bugfix/my-bugfix
) - Test your changes to the best of your ability.
- Commit your changes (
git commit -m 'Describe feature or bug'
) - Push to the branch (
git push origin feature/my-feature
) - Create a Github pull request
This repo includes a .editorconfig file, which your IDE should pickup automatically.
If not please use the sun coding convention. Please do not use tabs at all!
Try to change only parts your feature or bugfix requires.
MIT. Please see LICENSE.
This plugin is powered by BYTEOWLS Software & Consulting and was build for Team Conductor - Next generation club management platform.