- RubyMotion iOS Develoment Essentials
- Abhishek Nalwaya Akshat Paul
- 1419字
- 2021-08-13 16:43:55
Exploring the command line
RubyMotion is based on an underlying principle, "to use the tools which developers love". Therefore, to create an application using RubyMotion, we require only two tools; the first is your favorite editor and the second is the terminal. While developing a RubyMotion application, you will be required to familiarize yourself with the command line. Familiarity with the terminal always helps in faster and comfortable development.
Now that we have created our HelloWorld
application, let us explore a few commands that we have already used, and remember that RubyMotion uses them considerably. These commands are responsible for inaugurating our RubyMotion projects, motion
and rake
.
Motion command – one-stopshop
As used previously, the motion
command creates our RubyMotion project and also supports various other options. The motion
command is similar to the popular framework Ruby on Rails' rails
command. Before we go any further, let's fire up our terminal and see what can be done using the motion
command.
$ motion Usage: motion [-h, --help] motion [-v, --version] motion <command> [<args...>] Commands: account Access the software license account activate Activate the software license create Create a new project ri Display API reference update Update the software support Create a support ticket
motion account
: This displays the account/license information on the browser.motion activate
: If you want to activate your RubyMotion framework with a new license or if you have not yet activated the framework,motion activate
can be used.motion create <project name>
: This command will generate a RubyMotion project's skeleton that will have all the essential files needed to begin developing an iOS application.motion ri <API-name>
: This command helps us to find the documentation for the API that has been mentioned.motion update
: RubyMotion is a fast-moving framework and often requires updates.motion update
updates your framework from the command line itself.motion support
: There may be times when you have questions only an expert can answer.motion
support
helps you connect with RubyMotion directly, and you can ask a question by filling up a form. It can also be used for any feature request or for reporting a bug.
Rake tasks – get things done fast
Rake is a simple Ruby build program with capabilities similar to Make
. RubyMotion's rake
command has many predefined tasks that help you do several trivial jobs, such as compiling your code to test in a simulator or creating a package to test on a device, with ease. Let's fire up our terminal again and check what tasks can be performed using rake --tasks
.
$ rake ––tasks
The following table elaborates the different Rake tasks:

So Rake has plenty of tasks to do, but most importantly, out of all these tasks, if we simply run Rake, it will build and run our application on the iOS simulator.
Rake file – configuring your application
RubyMotion applications are highly configurable using different attributes in a Rakefile
. These attributes, by default, come with a sensible value but can be overridden with custom values. Let's explore each one of them—this section will come in handy, time and again, as we proceed with our application.
To see your current application configuration, run the rake config
task, and you will be presented with the following list:
$ rake config background_modes : [] build_dir : "./build" codesign_certificate : "Error" delegate_class : "AppDelegate" deployment_target : "6.0" device_family : :iphone entitlements : {} files : ["./app/app_delegate.rb", "./app/twitter.rb", "./app/twitter_controller.rb"] fonts : [] frameworks : ["UIKit", "Foundation", "CoreGraphics", "CoreGraphics"] icons : [] identifier : "com.yourcompany.MacBaconUI" interface_orientations : [:portrait, :landscape_left, :landscape_right] libs : [] motiondir : "/Library/RubyMotion" name : "MacBacon UI" prerendered_icon : false provisioning_profile : "Error" resources_dir : "./resources" sdk_version : "6.0" seed_id : "Error" short_version : "1" specs_dir : "./spec" status_bar_style : :default version : "1.0" weak_frameworks : [] xcode_dir : "/Applications/Xcode.app/Contents/Developer"
You can see the entire configuration settings for your application. These settings can be modified in a Rakefile
. You may find it easy to understand what these properties do by their names, but let us explain a few of them:
name
: This is where you can specify the name of your project as a string. By default, the name of your application will be the attribute that you passed duringmotion create
.version
: This variable saves the current application version as a string; it is 1.0 by default.identifier
: The project identifier is a string that is in reverse DNS—a naming convention that is in the reverse order of the domain name notation—such ascom.yourcompany.yourapp
.delegate_class
: This is where you specify your application delegate class as a string that is loaded once the application starts. The default value isAppDelegate
and the class is defined in theapp
/app_delegate.rb
file. However, we can rename theAppDelegate
class to a custom name of our choice and this then has to be updated in theRakefile
.Files
: This shows every.rb
file in theapp
directory in an array format. The default value is the result of executing the following expression:Dir.glob(./app/*/.rb)
framework
: This shows the names of the iOS frameworks that are used in our application in an array format. Soon you will be using many iOS frameworks, such as CoreFoundation, CoreMotion, and others, with your application. The build system is capable of dealing with dependencies, therefore they should be mentioned here. The default value is eitherUIKit
,Foundation
, orCoreGraphics
.libs
: This variable shows the library paths that are to be linked to the application in an array format. It contains the path to public system libraries, for example, /usr/lib/libz.dylib. The default value is[]
, an empty array.build_dir
: This variable is used to specify the directory path where you want the application build to be created in a string format. It must be relative to the project directory. The directory initially gets created automatically. In case it is not created, a temporary directory will be used instead. The default value isbuild
.resources_dir
: This variable is used to specify the directory for the resource files where all the images and icons go in a string format. It must be relative to the project directory. The default value isresources
.spec_dir
: This variable is used to specify the directory ofspec
files where all our test cases are present in a String format. The default value isspec
. It should be relative to the project directory.icons
: This variable lists the icons used for the application present in theresources
folder in anarray
format, for example,icon.png
and/oricon-72.png
. The files should be in tune with Apple's HIG (Human Interface Guidelines). By default, the value is[]
, an empty array.fonts
: This variable lists the names of the font files present in theresources
directory in anarray
format. These fonts will be taken into account while either generating the application bundle or testing on a simulator.prerendered_icon
: iOS application icons usually have a reflective shine on them. For that purpose, this property is used. If it is false, we will get the reflective shine on the icon. By default, the value is false.device_family
: With this property, we can specify which family of iOS device our application supports. The values can beiphone
,ipad
, or for universal application [:iphone
,:ipad
]. By default it is:iphone
.interface_orientations
: Apple iOS devices support various orientations for an application. They can beportrait
,landscape_left
,landscape_right
, orportrait_upside_down
. By default, the value is an array of:portrait
,:landscape_left
, or:landscape_right
.Xcode_dir
: This configuration tells us where the Xcode is installed.Note
Giving a new value to the
XCode_dir
property should generally be done first, before changing otherRakefile
properties.sdk_version
: This configuration lets us decide which SDK version will be used. By default, the value is the most recent version of the supported SDK.deployment_target
: This configuration shows which iOS SDK to target for the RubyMotion project. By default, the value is of the current SDK version that is installed, but this can be changed to any desired version of the iOS SDK, for example, 6.0 that will use iOS SDK Version 6.0.codesign_certificate
: This configuration shows which code-signing certificate is used. By default, the value is the first iPhone developer certificate in the keychain utility; for example, in our case it is iPhone developer: Paul Akshat (S3KPMT842Z).provisioning_profile
: This configuration variable specifies the path of the provisioning profile.seed_id
: The Apple provisioning profile has an identifier. This configuration shows us the same, which is usually the first application identifier picked from the provisioning profile.
- Learning Single:page Web Application Development
- Mastering Unity Shaders and Effects
- 基于Struts、Hibernate、Spring架構的Web應用開發
- Web性能實戰
- 深入解析Java編譯器:源碼剖析與實例詳解
- Tableau Desktop可視化高級應用
- UML軟件建模
- Dart:Scalable Application Development
- Python機器學習
- KnockoutJS Blueprints
- Learning Zimbra Server Essentials
- 流暢的Python
- Go語言編程之旅:一起用Go做項目
- Qt編程快速入門
- PHP從入門到精通(微視頻精編版)