Skip to content

artanisdesign/benCoding.SMS

 
 

Repository files navigation

benCoding.SMS Module

The benCoding.SMS module makes it easy to add SMS functionality into your iOS Titanium apps. We unleash the power of Apple's native Apple SMS component MFMessageComposeViewController to Titanium with an API fashioned after the Titanium EmailDialog to make it familiar to use.

Before you start

* This is an iOS module designed to work with Titanium SDK 1.8.1 or greater. * Before using this module you first need to install the package. If you need instructions on how to install a 3rd party module please read this installation guide.

Download the release

There is two ways you can download this module. The go to the releases/UseIfDownloadingFromGithub folder. This will have a release compiled for anyone download it from github.

You can also download it for free from Appcelerator's marketplace here.

Building from source?

If you are building from source you will need to do the following:

  • Modify the titanium.xcconfig file with the path to your Titanium installation
  • Make sure the the method moduleGUID in the class BencodingSmsModule has the variable marketPlace set to NO. This will avoid you running into any licensing issues.

Setup

  • Download the latest release from the releases folder ( or you can build it yourself )
  • Install the bencoding.sms module. If you need help here is a "How To" guide.
  • You can now use the module via the commonJS require method, example shown below.

var sms = require('bencoding.sms').createSMSDialog();

Now we have the module installed and avoid in our project we can start to use the components, see the feature guide below for details.

benCoding.SMS How To Example

For detailed documentation please reference this project's documentation folder. A code "How To" example is provided in the app.js located in the project's example folder.

Properties

This module provides access to most of the native MFMessageComposeViewController's functionality.

canSendText

Returns a boolean whether the device has the ability to send Text Messages. Please keep in mind this value will always be false when running on the simulator. (Read Only)

messageBody

The SMS message

toRecipients

An array of SMS recipients ie phone numbers

barColor

The bar color of the email dialog window when opened

Below is a description and example on how to use each supported method.


var sms = require('bencoding.SMS').createSMSDialog({
            barColor:'#336699', //set the SMS Dialog barColor
            messageBody:"Appcelerator Titanium Rocks!", //Set SMS Message
            toRecipients:[{"555-555-5555"},{"444-444-4444"}] //Who we are the SMS sending to
});

canSendText

This property returns a boolean indicator on whether or not sending SMS Messages is supported.

The below sample shows how you can check if this feature is supported.


Ti.API.info("Can I send messages?");
Ti.API.info("Is This Feature Supported? => " + sms.canSendText); 

//This is an example of how to check if the device can send Text Messages 
if(!sms.canSendText){ 
        var noSupport = Ti.UI.createAlertDialog({ 
           title:'Not Supported', 
           message:"This device doesn't support sending text messages" }).show(); 
      return; 
}

Methods

setBarColor

Sets the barColor property for the SMS Dialog, see below for an example on how to use this.

setToRecipients

Sets the toRecipients property with an array ( ie an array of phone numbers),see below for an example on how to use this.

setMessageBody

Sets the messageBody property with a string. This is used to set the message shown in the SMSDialog,see below for an example on how to use this.

open

This opens the SMS dialog. The SMS dialog itself is a modal window.

Method Usage Example

The below example shows how to use all of the methods. For additional samples please see the example folder contained within the module or [here on Github](https://github.com/benbahrenburg/benCoding.SMS/tree/master/example).

//Set the SMS BarColor
sms.setBarColor('#336699');

//Set the SMS message, you can also do this when you create the SMSDialog
sms.setMessageBody("Appcelerator Titanium Rocks!");

//Set the SMS ToRecipients, you can also do this when you create the SMSDialog
//This is an array so you can pass in several numbers for the message to be sent to
sms.setToRecipients([{"555-555-5555"},{"444-444-4444"}]);

//This call opens the SMS Message Dialog window withe number and message you provided earlier
sms.open({ 
    animated:true //Indicate if the dialog should be animated on open (OPTIONAL) 
}); 	

Events

completed

This event is fired when the user presses the cancel button on the SMS Dialog

cancelled

This event is fired when an SMS message is sent successfully

errored

This event is fired when an error happens sending a message

Event Usage Example

The below example shows how to use all of the events. Please note the events will not become active until the open method is called.

For additional samples please see the example folder contained within the module or here on Github.


var sms = require('bencoding.sms').createSMSDialog({ barColor:'#336699' });

//If you want you can define some callbacks
function messageCompleted(e){
    alert(e.message); 
};
function messageErrored(e){
    alert(e.message); 
};

function messageCancelled(e){
    alert(e.message); 
};

//Add the listeners so we know when an action happens
sms.addEventListener('cancelled', messageCancelled);
sms.addEventListener('completed', messageCompleted);
sms.addEventListener('errored', messageErrored);

FAQ

Can I automately send the SMS message without showing it to the user?

No, this is not supported by Apple.

Can I send a MMS?

No, the current Apple API does not allow for this.

Can I change the style of the dialog?

You can update the barColor by setting the barColor property when creating the SMSDialog or by calling the setBarColor method before calling the open method.

Is there an Android version?

You can do this using activities on Android without the need of a module. This module is an iOS only wrapper around the native [MFMessageComposeViewController](https://developer.apple.com/library/ios/#documentation/MessageUI/Reference/MFMessageComposeViewController_class/Reference/Reference.html) component.

Licensing & Support

This project is licensed under the OSI approved Apache Public License (version 2). For details please see the license associated with each project.

Developed by Ben Bahrenburg available on twitter @benCoding

Learn More

Twitter

Please consider following the @benCoding Twitter for updates and more about Titanium.

Blog

For module updates, Titanium tutorials and more please check out my blog at benCoding.Com.

About

SMS Dialog Module for Titanium Mobile

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published