Pugalmuni
Pugalmuni

Reputation: 9390

How to Create SMS application in iPhone

I am new to iphone development, i want to create SMS application in my application.I have created mail application using "messageUI.framework".Is there any framework for creating SMS application.I have no idea of it, so tell me the way of approaching this task. Please guide me to achieve my task.Please help me out.Thanks.

Upvotes: 2

Views: 4543

Answers (4)

Janmenjaya
Janmenjaya

Reputation: 4163

MFMessageComposeViewController will send the message through iMessage app. But If you want to send sms through network career of your iPhone then following code will help you

    NSString *phoneToCall = @"sms:";
NSString *phoneToCallEncoded = [phoneToCall stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSURL *url = [[NSURL alloc] initWithString:phoneToCallEncoded];
[[UIApplication sharedApplication] openURL:url];

Upvotes: 0

Brad Larson
Brad Larson

Reputation: 170309

Unfortunately, there is no built-in view controller for sending SMS like MFMailComposeViewController for email.

As of iOS 4.0, you can use the MFMessageComposeViewController, a counterpart to the email-only MFMailComposeViewController. This lets you lay out and send an SMS message.

Additionally, you can use the SMS URL scheme, like is decribed in this question. However, it appears that you cannot prepopulate the body of an SMS message this way.

Upvotes: 2

Siba Prasad Hota
Siba Prasad Hota

Reputation: 4789

You can use the MFMessageComposeViewController class, as documented by Apple.

For that, first add MessageUI.framework to your project.

// in .h file make the following change

#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMessageComposeViewController.h>

@interface YourViewController: UIViewController <MFMessageComposeViewControllerDelegate>

// then in .m file do the following.

- (void)viewDidLoad {
    [super viewDidLoad];

SMSLabel = [[UILabel alloc] initWithFrame:CGRectMake(30.0, 340.0, 260.0, 30.0)];
    SMSLabel .frame = CGRectMake(30.0, 340.0, 260.0, 30.0);
    SMSLabel .adjustsFontSizeToFitWidth = YES;
    SMSLabel .hidden = YES;
    SMSLabel .text = @"";
    SMSLabel .userInteractionEnabled = NO;
    SMSLabel.alpha=0.0;
    [self.view addSubview:SMSLabel ];  


}

-(void)ComposerSheet 
{
    MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
    picker.messageComposeDelegate = self;

    picker.recipients = [NSArray arrayWithObject:@"1234567"];  
    picker.body = @"iPhone OS4";

    [self presentModalViewController:picker animated:YES];
    [picker release];

}

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
    SMSLabel.alpha=1.0;

    switch (result)
    {
        case MessageComposeResultCancelled:
            SMSLabel .text = @"Result: canceled";
            NSLog(@"Result: canceled");
            break;
        case MessageComposeResultSent:
            SMSLabel .text = @"Result: sent";
            NSLog(@"Result: sent");
            break;
        case MessageComposeResultFailed:
            SMSLabel .text = @"Result: failed";
            NSLog(@"Result: failed");
            break;
        default:
            SMSLabel .text = @"Result: not sent";
            NSLog(@"Result: not sent");
            break;
    }

    [self dismissModalViewControllerAnimated:YES];

}

Upvotes: 2

coneybeare
coneybeare

Reputation: 33101

Sending messages is somewhat easy — you can usually send an email to a specially formatted number like [email protected] (example only, not sure of real format) and it will send to the device. There is not going to be an easy way to receive sms messages in your app natively.

You can, however, try using one of many free sms apis such as ZeepMobile

Upvotes: 1

Related Questions