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.
* The SMS.Dialog module can only be tested on the device itself. This is an Apple Simulator limitation and not a module feature. * If you are using iOS 6 or a Titanium SDK greater then 1.8.2 please read the iOS 6 section below. * This is an iOS module designed to work with Titanium SDK 1.8.2. * 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. If you are building for iOS 6 using Xcode 4.5 or greater you need to use SMS.Dialog 1.8 or greater. This version of the SMS.Dialog requires using the 2.1.4GA Titanium SDK.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.
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.
- 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.
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.
This module provides access to most of the native MFMessageComposeViewController's functionality.
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) The SMS message An array of SMS recipients ie phone numbers The bar color of the email dialog window when openedBelow 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
});
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;
}
//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)
portraitOnly:true //Indicate if we lock the dialog into the portrait orientation only (OPTIONAL)
});
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);
If you want to lock into portrait only you can do so by adding the portraitOnly parameter to the open method.
No, this is not supported by Apple. No, the current Apple API does not allow for this. 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. 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.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
Please consider following the @benCoding Twitter for updates and more about Titanium.
For module updates, Titanium tutorials and more please check out my blog at benCoding.Com.