-3

How do you send an in-app sms (text message) from an iPone app written in Rubymotion?

jjnevis
  • 2,672
  • 3
  • 22
  • 22

1 Answers1

3

Okay, so I've figured out one way to do this, thanks to: https://github.com/ParkinT/RubyMotion_APISampler

make sure you put this in your Rakefile:

app.frameworks += %w[MessageUI]

Then here's the code for your view controller:

def send_sms
  MFMessageComposeViewController.alloc.init.tap do |sms|
    sms.messageComposeDelegate = self
    sms.recipients = ["012345678", '000000000']
    sms.body = "Hello World!"
    self.presentModalViewController(sms, animated:true)
  end if MFMessageComposeViewController.canSendText
end

def messageComposeViewController(controller, didFinishWithResult:result)
  NSLog("SMS Result: #{result}")
  controller.dismissModalViewControllerAnimated(true)
end

The second method is a callback that you need to implement in order to close the sms modal and you may want to handle the various results better or do other things, but that's the gist of it. Clone the repository above and have a play around.

Hope this helps, certainly got me going.

jjnevis
  • 2,672
  • 3
  • 22
  • 22