0

I have a button on each cell of my table. When the button is pressed I want the sms screen to open and have it prepopulate with a unique link.

I've done this in Android using android.intent.action.SEND but I'm not sure how to do it in iOS. In Android when the user clicks the button, the Android automatically gives the user several options to share the url (Facebook/twitter/sms/gmail/etc). I would prefer this to happen, but if this isn't possible then opening the SMS screen would be sufficient.

I would imagine something like this would be possible in iOS?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Anthony
  • 33,838
  • 42
  • 169
  • 278

2 Answers2

1

I'd recommend using UIActivityViewController as this should show all of the apps on the device which are capable of sending the link. This will only work for setting the contents of the message though; unfortunately, it doesn't seem like it's possible to set the recipient using this technique.

NSString *text = @"Click on this link!!";
NSURL *url = [NSURL URLWithString:@"http://google.com"];

NSArray *itemsToShare = @[text, url];

UIActivity *activity = [[UIActivity alloc] init];
NSArray *applicationActivities = [[NSArray alloc] initWithObjects:activity, nil];
UIActivityViewController *activityVC =
        [[UIActivityViewController alloc] initWithActivityItems:itemsToShare
                                          applicationActivities:applicationActivities];

[self presentViewController:activityVC
                       animated:YES
                     completion:nil];

enter image description here


If you know you definitely want to send an SMS (rather than letting the user decide) then there are a few other options.

MFMessageComposeViewController

The following web page does a really good job of explaining how to do this: http://www.appcoda.com/ios-programming-send-sms-text-message

Open SMS: URL

It's possible to show the SMS composer using a simple "SMS:" link but you can only pre-populate the recipient's phone number, not the message, so this probably won't be good enough for what you need. For example:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms:1-408-555-1212"]];

https://developer.apple.com/library/ios/featuredarticles/iPhoneURLScheme_Reference/SMSLinks/SMSLinks.html

Ian
  • 7,480
  • 2
  • 47
  • 51
  • awesome. I'm not looking to set the recipient anyways. Thanks for your answer. I'll look to convert it to rubymotion now :) – Anthony Apr 06 '14 at 17:45
0

The answer to this question can be found by searching StackOverflow. It has been asked multiple times before.

Essentially, MFMessageComposeViewController is your friend. There are various tutorials you can find by using Google.

CocoaDog
  • 305
  • 1
  • 11