Open Message app (SMS app) with a button and a Text field/View (iPhone)












3















Would this be possible?



The app will have a button and a Text Field or a Text View.



The user types in the phone number in the Text Field or Text View. when the user is done the user presses the button which will open the Message or SMS app in the iPhone.



How would I do this? If possible please provide some code! :)



Thank you in advance!










share|improve this question



























    3















    Would this be possible?



    The app will have a button and a Text Field or a Text View.



    The user types in the phone number in the Text Field or Text View. when the user is done the user presses the button which will open the Message or SMS app in the iPhone.



    How would I do this? If possible please provide some code! :)



    Thank you in advance!










    share|improve this question

























      3












      3








      3


      1






      Would this be possible?



      The app will have a button and a Text Field or a Text View.



      The user types in the phone number in the Text Field or Text View. when the user is done the user presses the button which will open the Message or SMS app in the iPhone.



      How would I do this? If possible please provide some code! :)



      Thank you in advance!










      share|improve this question














      Would this be possible?



      The app will have a button and a Text Field or a Text View.



      The user types in the phone number in the Text Field or Text View. when the user is done the user presses the button which will open the Message or SMS app in the iPhone.



      How would I do this? If possible please provide some code! :)



      Thank you in advance!







      iphone objective-c sms message






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Feb 1 '11 at 14:08









      TapyTapy

      66851328




      66851328
























          3 Answers
          3






          active

          oldest

          votes


















          8














          Take a look at the MessageComposer Sample App and the MFMessageComposeViewController Class.



          You then do something like this, though you should first check whether the MFMessageComposeViewController is actually available on your device (See the MessageComposer Sample):



          MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
          picker.messageComposeDelegate = self;
          picker.recipients = [NSArray arrayWithObjects:@"1234", @"2345", nil];
          picker.body = yourTextField.text

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


          You need to first import the MessageUI.framework (see this answer).



          Import it into your classes via #import <MessageUI/MessageUI.h> and add <MFMessageComposeViewControllerDelegate> in the .h file, e.g. like so:



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

          @interface YourClass : UIViewController <MFMessageComposeViewControllerDelegate>
          {
          // ...





          share|improve this answer


























          • Thank you! I'll try that

            – Tapy
            Feb 1 '11 at 19:59



















          6














          Another short way, may help anyone much better :)



          NSString *sms = @"sms:+1234567890&body=This is sms body.";
          NSString *url = [sms stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
          [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];





          share|improve this answer

































            0














            In Swift 3.0



            static func sendMessageToNumber(number:String,message:String){

            let sms = "sms:(number)&body=(message)"
            let url = URL(string:sms)!
            let shared = UIApplication.shared

            if(shared.canOpenURL(url)){
            shared.openURL(url)
            }else{
            print("unable to send message")
            }
            }





            share|improve this answer























              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f4863535%2fopen-message-app-sms-app-with-a-button-and-a-text-field-view-iphone%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              8














              Take a look at the MessageComposer Sample App and the MFMessageComposeViewController Class.



              You then do something like this, though you should first check whether the MFMessageComposeViewController is actually available on your device (See the MessageComposer Sample):



              MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
              picker.messageComposeDelegate = self;
              picker.recipients = [NSArray arrayWithObjects:@"1234", @"2345", nil];
              picker.body = yourTextField.text

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


              You need to first import the MessageUI.framework (see this answer).



              Import it into your classes via #import <MessageUI/MessageUI.h> and add <MFMessageComposeViewControllerDelegate> in the .h file, e.g. like so:



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

              @interface YourClass : UIViewController <MFMessageComposeViewControllerDelegate>
              {
              // ...





              share|improve this answer


























              • Thank you! I'll try that

                – Tapy
                Feb 1 '11 at 19:59
















              8














              Take a look at the MessageComposer Sample App and the MFMessageComposeViewController Class.



              You then do something like this, though you should first check whether the MFMessageComposeViewController is actually available on your device (See the MessageComposer Sample):



              MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
              picker.messageComposeDelegate = self;
              picker.recipients = [NSArray arrayWithObjects:@"1234", @"2345", nil];
              picker.body = yourTextField.text

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


              You need to first import the MessageUI.framework (see this answer).



              Import it into your classes via #import <MessageUI/MessageUI.h> and add <MFMessageComposeViewControllerDelegate> in the .h file, e.g. like so:



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

              @interface YourClass : UIViewController <MFMessageComposeViewControllerDelegate>
              {
              // ...





              share|improve this answer


























              • Thank you! I'll try that

                – Tapy
                Feb 1 '11 at 19:59














              8












              8








              8







              Take a look at the MessageComposer Sample App and the MFMessageComposeViewController Class.



              You then do something like this, though you should first check whether the MFMessageComposeViewController is actually available on your device (See the MessageComposer Sample):



              MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
              picker.messageComposeDelegate = self;
              picker.recipients = [NSArray arrayWithObjects:@"1234", @"2345", nil];
              picker.body = yourTextField.text

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


              You need to first import the MessageUI.framework (see this answer).



              Import it into your classes via #import <MessageUI/MessageUI.h> and add <MFMessageComposeViewControllerDelegate> in the .h file, e.g. like so:



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

              @interface YourClass : UIViewController <MFMessageComposeViewControllerDelegate>
              {
              // ...





              share|improve this answer















              Take a look at the MessageComposer Sample App and the MFMessageComposeViewController Class.



              You then do something like this, though you should first check whether the MFMessageComposeViewController is actually available on your device (See the MessageComposer Sample):



              MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
              picker.messageComposeDelegate = self;
              picker.recipients = [NSArray arrayWithObjects:@"1234", @"2345", nil];
              picker.body = yourTextField.text

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


              You need to first import the MessageUI.framework (see this answer).



              Import it into your classes via #import <MessageUI/MessageUI.h> and add <MFMessageComposeViewControllerDelegate> in the .h file, e.g. like so:



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

              @interface YourClass : UIViewController <MFMessageComposeViewControllerDelegate>
              {
              // ...






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited May 23 '17 at 12:13









              Community

              11




              11










              answered Feb 1 '11 at 14:18









              fabian789fabian789

              5,73843683




              5,73843683













              • Thank you! I'll try that

                – Tapy
                Feb 1 '11 at 19:59



















              • Thank you! I'll try that

                – Tapy
                Feb 1 '11 at 19:59

















              Thank you! I'll try that

              – Tapy
              Feb 1 '11 at 19:59





              Thank you! I'll try that

              – Tapy
              Feb 1 '11 at 19:59













              6














              Another short way, may help anyone much better :)



              NSString *sms = @"sms:+1234567890&body=This is sms body.";
              NSString *url = [sms stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
              [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];





              share|improve this answer






























                6














                Another short way, may help anyone much better :)



                NSString *sms = @"sms:+1234567890&body=This is sms body.";
                NSString *url = [sms stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];





                share|improve this answer




























                  6












                  6








                  6







                  Another short way, may help anyone much better :)



                  NSString *sms = @"sms:+1234567890&body=This is sms body.";
                  NSString *url = [sms stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                  [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];





                  share|improve this answer















                  Another short way, may help anyone much better :)



                  NSString *sms = @"sms:+1234567890&body=This is sms body.";
                  NSString *url = [sms stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                  [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jun 8 '16 at 6:30

























                  answered Jun 8 '16 at 6:25









                  Mohd AsimMohd Asim

                  7811012




                  7811012























                      0














                      In Swift 3.0



                      static func sendMessageToNumber(number:String,message:String){

                      let sms = "sms:(number)&body=(message)"
                      let url = URL(string:sms)!
                      let shared = UIApplication.shared

                      if(shared.canOpenURL(url)){
                      shared.openURL(url)
                      }else{
                      print("unable to send message")
                      }
                      }





                      share|improve this answer




























                        0














                        In Swift 3.0



                        static func sendMessageToNumber(number:String,message:String){

                        let sms = "sms:(number)&body=(message)"
                        let url = URL(string:sms)!
                        let shared = UIApplication.shared

                        if(shared.canOpenURL(url)){
                        shared.openURL(url)
                        }else{
                        print("unable to send message")
                        }
                        }





                        share|improve this answer


























                          0












                          0








                          0







                          In Swift 3.0



                          static func sendMessageToNumber(number:String,message:String){

                          let sms = "sms:(number)&body=(message)"
                          let url = URL(string:sms)!
                          let shared = UIApplication.shared

                          if(shared.canOpenURL(url)){
                          shared.openURL(url)
                          }else{
                          print("unable to send message")
                          }
                          }





                          share|improve this answer













                          In Swift 3.0



                          static func sendMessageToNumber(number:String,message:String){

                          let sms = "sms:(number)&body=(message)"
                          let url = URL(string:sms)!
                          let shared = UIApplication.shared

                          if(shared.canOpenURL(url)){
                          shared.openURL(url)
                          }else{
                          print("unable to send message")
                          }
                          }






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Jul 26 '17 at 12:26









                          Rohit PathakRohit Pathak

                          319416




                          319416






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f4863535%2fopen-message-app-sms-app-with-a-button-and-a-text-field-view-iphone%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Wiesbaden

                              Marschland

                              Dieringhausen