Creating an iOS Project with Forceios

To create an app, use forceios in a terminal window. The forceios utility gives you two ways to create your app.
  • Specify the type of application you want, along with basic configuration data.

    or

  • Use an existing Mobile SDK app as a template. You still provide the basic configuration data.
You can use forceios in interactive mode with command-line prompts, or in script mode with command-line arguments. To see command usage information, type forceios without arguments.

Be sure to install CocoaPods before using forceios. See iOS Preparation.

Note

Forceios Application Types

For application type, the forceios create command accepts either of the following input values:

App Type Language
Type native_swift (or press RETURN) Swift
Type native Objective-C

Using forceios create Interactively

To use interactive prompts to create an app, open a Terminal window and type forceios create. For example:
1$ forceios create
2Enter your application type (native, native_swift): <press RETURN>
3Enter your application name: testSwift
4Enter the package name for your app (com.mycompany.myapp): com.bestapps.ios
5Enter your organization name (Acme, Inc.): BestApps.com
6Enter output directory for your app (leave empty for the current directory): testSwift
This command creates a native iOS Swift app named “testSwift” in the testSwift/ subdirectory of your current directory.

Using forceios create in Script Mode

In script mode, you can use forceios without interactive prompts. For example, to create a native app written in Swift:
1$ forceios create --apptype="native_swift" --appname="package-test" --packagename="com.acme.mobile_apps" 
2    --organization="Acme Widgets, Inc." --outputdir="PackageTest"
Or, to create a native app written in Objective-C:
1$ forceios create --apptype="native" --appname="package-test" --packagename="com.acme.mobile_apps" 
2    --organization="Acme Widgets, Inc." --outputdir="PackageTest"

Each of these calls creates a native app named “package-test” and places it in the PackageTest/ subdirectory of your current directory.

Creating an App from a Template

The forceios createWithTemplate command is identical to forceios create except that it asks for a GitHub repo URI instead of an app type. You set this URI to point to any repo directory that contains a Mobile SDK app that can be used as a template. Your template app can be any supported Mobile SDK app type. The script changes the template’s identifiers and configuration to match the values you provide for the other parameters.

Before you use createWithTemplate, it's helpful to know which templates are available. To find out, type forceios listtemplates. This command prints a list of templates provided by Mobile SDK. Each listing includes a brief description of the template and its GitHub URI. For example:
1Available templates:
2
31) Swift application using MobileSync, SwiftUI and Combine
4forceios createwithtemplate --templaterepouri=iOSNativeSwiftTemplate
5
62) Swift application using MobileSync, SwiftUI and Combine (pulled in using Swift Package Manager)
7forceios createwithtemplate --templaterepouri=iOSNativeSwiftPackageManagerTemplate
8
93) Basic Swift application with notification service extension
10forceios createwithtemplate --templaterepouri=iOSNativeSwiftEncryptedNotificationTemplate
11
124) Basic Objective-C application
13forceios createwithtemplate --templaterepouri=iOSNativeTemplate
14
155) Sample Swift Identity Provider application
16forceios createwithtemplate --templaterepouri=iOSIDPTemplate
17
186) Sample Swift application using MobileSync data framework
19forceios createwithtemplate --templaterepouri=MobileSyncExplorerSwift
Once you've found a template's URI, you can plug it into the forceios command line. Here’s command-line usage information for forceios createWithTemplate:
1Usage:
2forceios createWithTemplate 
3    --templaterepouri=<Template repo URI> (e.g., MobileSyncExplorerReactNative)] 
4    --appname=<Application Name> 
5    --packagename=<App Package Identifier> (e.g. com.mycompany.myapp) 
6    --organization=<Organization Name> (Your company's/organization's name) 
7    --outputdir=<Output directory> (Leave empty for current directory)]
For any template in the SalesforceMobileSDK-Templates repo, you can drop the path for templaterepouri—just the template name will do. For example:
1forceios createwithtemplate --templaterepouri=iOSNativeSwiftTemplate
You can use forceios createWithTemplate interactively or in script mode. For example, here’s a script mode call that uses a specific tag for the template:
1forceios createWithTemplate 
2--templaterepouri=MobileSyncExplorerSwift
3--appname=MyMobileSyncExplorer 
4-—packagename=com.mycompany.react 
5--organization="Acme Software, Inc." 
6-—outputdir=testWithTemplate
This call creates a native Swift app with the same source code and resources as the MobileSyncExplorerSwift sample app. Forceios places the new app in the testWithTemplate/ subdirectory of your current directory. It also changes the app name to “MyMobileSyncExplorer” throughout the project.

Checking the Forceios Version

To find out which version of forceios you’ve installed, run the following command:
1forceios version

Running Your New forceios Project

Apps created with forceios are ready to run, right out of the box. After forceios finishes, it prints instructions for opening and running the project from the command line.

If you prefer, you can leave the command line and open your new project manually in Xcode.
  1. In Xcode, select File | Open.
  2. Navigate to the output folder you specified.
  3. Open the workspace file (<project_name>.xcworkspace).
  4. When Xcode finishes building, click the Run button.
 .

How the Forceios Script Generates New Apps

  • Apps are based on CocoaPods or Swift Package Manager.
  • The script downloads templates at runtime from a GitHub repo.
  • For the forceios create command, the script uses the default templates in the SalesforceMobileSDK-Templates GitHub repo.
  • For templates based on CocoaPods, the script uses npm at runtime to download Mobile SDK libraries. The podfile refers to these libraries with :path => node_modules/... directives.
  • For projects built with Swift Package Manager, the script configures the Xcode project to use the Salesforce Mobile SDK Swift Package published on https://github.com/forcedotcom/SalesfoceMobileSDK-iOS-SPM.