sending sms from iphone app

You must Login before you can answer or comment on any questions.

i tried sending sms programmatically from an iPhone app using the following two modules but I am running into one issue in both cases.

https://github.com/omorandi/TiSMSDialog https://github.com/benbahrenburg/benCoding.SMS

After sending the sms (after sms dialog disappears), my app window becomes unresponsive (text fields are not editable, etc.). I am wondering if anybody else who has used these modules have experienced something similar? I tried the sample apps that module provides and even the examples have this same issue.

Any help is appreciated.

1 Answer

Accepted Answer

Hi Saqib

I have used the TiSMSDialog module and it works correctly, I am not seeing the same issue as you.

I used the exact same code as the example supplied with the module, only changing the phone number when the dialog is shown, before sending. Obviously this needs to be done on the physical phone as the simulator does not support this function.

I added the module into the Modules folder of the project rather than globally, in case that might be different from your use.

Exact code used shown below. This was triggered by a left nav button and sat above a table. Once the sms was successfully sent I continued to have normal use of the app.

var SMS = require('ti.sms');
var sms = SMS.createSMSDialog({
    animated: true
});
sms.barColor = 'black';
sms.toRecipients = [
    '5678309' // who should receive the text? put their numbers here!
];
sms.messageBody = 'This is a text message.';
sms.addEventListener('complete', function(evt) {
    if (evt.success) {
        alert('SMS sent!');
    }
    else {
        switch (evt.result) {
            case SMS.CANCELLED:
                alert('User cancelled SMS!');
                break;
            case SMS.FAILED:
            default:
                alert(evt.error);
                break;
        }
    }
});
sms.open();

— answered 11 months ago by Malcolm Hollingsworth
answer permalink
17 Comments
  • I appreciate your response Malcolm. If you don't mind spending a few mins, could you please try and install the following example on your phone. I would really appreciate it.

    https://github.com/benbahrenburg/benCoding.SMS/tree/master/example

    — commented 11 months ago by Saqib Khalil

  • I have tried the benCoding version as you requested and have had successes and failures.

    Test 1. Using the (almost) exact code as provided with the example only changing to allow it to sit on my test app window. I could not view the button at this point so I added an underlying scrollview. I was then able to press the button. This allowed me to send the sms then I DID experience the same inability to select the text fields form the example.

    Test 2. Stripped the whole code back down to just a button on the navbar and the following lines of code; Obviously changing the number prior to send.

    var sms = require('bencoding.sms').createSMSDialog({ barColor:'#336699' });
    sms.addEventListener('cancelled', function (e) { alert(e.message); });
    sms.addEventListener('completed', function (e) { alert(e.message); });
    sms.addEventListener('errored', function (e) { alert(e.message); });
     
    sms.setMessageBody('This is a text message.');
    sms.setToRecipients(['5678309']);
    sms.open({
        animated: true
    });
    This DID NOT suffer the same problem and correctly sent the sms and then allowed full access to the rest of the app. Note that there were NO other controls on the same window.

    Test 3. Used the code above but this time added a couple of the same text fields from the original code.

    var numbertText = Ti.UI.createTextField({
        value: '07525780269',
        height:35,
        top: 10,
        left:10,
        right:10,
        keyboardType:Ti.UI.KEYBOARD_NUMBERS_PUNCTUATION,
        returnKeyType:Ti.UI.RETURNKEY_DONE, 
        borderStyle:Ti.UI.INPUT_BORDERSTYLE_ROUNDED
    });
    win.add(numbertText);
     
    var msgText = Ti.UI.createTextField({
        value: 'SMS Test',
        height:50,
        top: 80,
        left:10,
        right:10,   
        returnKeyType:Ti.UI.RETURNKEY_DONE, 
        borderStyle:Ti.UI.INPUT_BORDERSTYLE_ROUNDED
    });
    win.add(msgText);
     
    var btnTest = Ti.UI.createButton({
        title: 'SMS'
    });
    win.setLeftNavButton(btnTest);
    btnTest.addEventListener('click', function (e) {
        var sms = require('bencoding.sms').createSMSDialog({ barColor:'#336699' });
        sms.addEventListener('cancelled', function (e) { alert(e.message); });
        sms.addEventListener('completed', function (e) { alert(e.message); });
        sms.addEventListener('errored', function (e) { alert(e.message); });
     
        sms.setMessageBody(msgText.getValue());
        sms.setToRecipients([numbertText.getValue()]);
        sms.open({
            animated: true
        });
    });
    This DID experience the same issues you noted and also failed in the same way as test 1.

    There does appear to be an issue - it is not just you. I am using 2.1 on a mac and iOS 5.1, for comparison.

    — commented 11 months ago by Malcolm Hollingsworth

  • I really appreciate your time Malcolm and for validating the three scenarios. I wonder if both modules suffer a problem when there are other text fields involved.

    — commented 11 months ago by Saqib Khalil

  • Show 14 more comments

Your Answer

Think you can help? Login to answer this question!