Developing Salesforce Mobile Apps with RubyMotion

RubyMotion, a revolutionary new toolchain for native iOS development from HipByte, lets developers write iOS apps in Ruby, rather than Objective-C. It statically compiles ruby code to run on the Objective-C runtime, and because of this, RubyMotion apps have full access to all the public API’s and Frameworks available to traditional Objective-C developers. This includes not only the basic UIKit framework for application development, but also hardware specific bits like coreLocation.  Additionally, the wealth of open source control and libraries available through Cocoapods are also now fully available to RubyMotion developers.

How To Get Started With RubyMotion
SalesForce provides iOS mobile developers a rich SDK that handles Authentication (via Oauth2), query building and execution, and json deserialization. Developers eager to get started now can find the SDK here: Salesforce Mobile SDK (iOS)

Ideally all third-party libraries, frameworks and sdk’s would be available as cocoa pods; however the Salesforce SDK consists of multiple individual libraries and is not available as a cocoapd (yet, click here to read more about this issue)

Instead, the various pieces and parts of the SDK must be incorporated into your rubymotion project via the rakefile’s vendor and libs directives. Click here for an annotated rakefile detailing the what, how and why of incorporating the Salesforce Mobile SDK(iOS) into your RubyMotion project. With this rakefile as a starting point and guide, you can create apps that interact with Salesforce with Rubymotion!

Some Important Notes:

  1. This rakefile assumes you have placed your salesforce sdk in: «ProjectRoot»/vendor/Salesforce
  2. Note how some of the Salesforce SDK pieces are included via the app.libs « directive. These are precompiled, distribution ready .a files that Salesforce provides.
  3. However, not all of the Salesforce SDK pieces can be utilized by RubyMotion when incorporated via app.libs. Specifically, any piece of the SDK your application will be directly calling must be compiled by RubyMotion. RubyMotion exposes Obj-c methods by generating a .bridgeSupport file. These files are generated from the .h header files included with the source. These pieces are incorporated via the app.vendor_project directive.
  4. Please note that RestKit, SalesforceOAuth, and SalesforceSDK must all be included via app.vendor_project. When including other vendor projects always be sure to include the :headers => hash element so that the bridgesupport file is created.

A Note On Translating Example Objective-C Code To RubyMotion Specific To The Salesforce SDK.
The example code for querying the Salesforce RestAPI looks something like this:

[[SFRestAPI sharedInstance] performSOQLQuery:”QueryString” failBlock:^{stuff} completeBlock:^{Other stuff}]

This Objective-C code is translated to RubyMotion thusly:

SFRestAPI.sharedInstance.performSOQLQuery(“query string”, failBlock: lambda {|e| stuff }, completeBlock:lambda{|c| otherStuff} )

Note that RubyMotion is expecting Lambdas as the blocks for failBlock and completeBlock.

Protip: The Ruby method named “method” (i kid you not) operates as a lambda, thus you can say: completeBlock: method(:some_method_name) and when the completeBlock is run, it will execute your method.

Very handy!

Questions About Salesforce Development?
We are home to some of the best Salesforce developers in the industry. If you have questions about this new application, or other related Salesforce development questions, please feel free to leave a comment, or contact us directly. You can also sign up for our newsletter, which provides advice, insight, and tips on how to get the most out of your Salesforce setup, as well as free software downloads, product reviews, and more.

Phone: 312-602-4000
Email: marketing@westmonroepartners.com
222 W. Adams
Chicago, IL 60606
Show Buttons
Share On Facebook
Share On Twitter
Share on LinkedIn
Hide Buttons