views:

63

answers:

2

hi to all,

i have created a music greetings application in iphone. I want that when a user enters his mobile number in the text field and clicks on the send button data from another view should be fetched and send an sms to user's mobile number.

Please anybody help me in solving this problem

A: 

this link is useful to you even sample code is also their

this is for only ios4

http://developer.apple.com/iphone/library/navigation/index.html#section=Frameworks&topic=Message%20UI

priyanka
+1  A: 

Apple only supports sending sms through the UI they provide. To do so, first Check that you can send a sms. Use NSClassFromString to detect the presence of MFMessageComposeViewController in case you are deploying to an older version of iOS that does not support this, and check that if MFMessageComposeViewController does exist that canSendText return true. It would return false if the user's device does not have sms capability:

  if ([[NSClassFromString(@"MFMessageComposeViewController") canSendText]) {
    [self presentMessageComposeViewController];
  }  

If the device and OS support it now present a MFMessageComposeViewController from a view controller in your app. This method should be implement in a subclass of UIViewController that is managing the current view:

-(void) presentMessageComposeViewController {
    id smsViewController = [[NSClassFromString(@"MFMessageComposeViewController") alloc] init];
        [smsViewController setTitle:NSLocalizedString(@"Your Title",nil)];
    [smsViewController setBody:NSLocalizedString(@"Your Message. urls work too www.example.com",nil)];
    [smsViewController setMessageComposeDelegate: (id)self];
    [self presentModalViewController:smsViewController animated:YES];
    [smsViewController release];
}

You will also need to implement the delegate method to dismiss the MFMessageComposeViewController:

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
    [self dismissModalViewControllerAnimated:YES];
}

If you need to use your own UI, you are going to have to talk to your own server, or a third party service that can send the sms for you. For example, using the Twilio API (and the ASIHTTPRequest project):

NSString *urlString = [NSString stringWithFormat:
@"http://api.twilio.com/2010-04-01/Accounts/%@/SMS/Messages,kYourTwillioSID];
NSURL = [NSURL urlWithString:urlString];
SIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:yourPhoneNumber forKey:@"TO"];
[request setPostValue:@yourBody forKey:@"Body"];
[request setFile:kYourOutgoingTwilioNumber forKey:@"From"];
Brad Smith
thank sir,i am deploying on my iphone which has a maximum version of 3.1.2. Does that support sms sending functionality
Pradeep
looking at the MFessageComposeViewController.h I see that the relevant methods are flagged __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_0) so it looks like you would need 4.0 or greater to use the built in solution. Using twilio.com or another service would work with any version
Brad Smith