To develop iOS apps with Liferay Screens, you must first install and configure Screens in your iOS project. Screens is released as a standard CocoaPods dependency. You must therefore install Screens via CocoaPods. After completing the installation, you must configure your iOS project to communicate with your portal instance. This tutorial walks you through these processes. You’ll be up and running in no time!
First, you’ll review the requirements for Liferay Screens.
Liferay Screens for iOS includes the Component Library (the Screenlets) and some sample projects written in Swift. Screens is developed using Swift and development techniques that leverage functional Swift code and the Model View Presenter architecture. You can use Swift or Objective-C with Screens, and you can run Screens apps on iOS 9 and above.
Liferay Screens for iOS requires the following software:
- Xcode 9 or newer
- iOS 11 SDK
- CocoaPods 1 or newer
- Liferay Portal 6.2 CE/EE, 7.0 CE, Liferay DXP
- Liferay Screens Compatibility Plugin (CE or EE, depending on your portal edition). This app is preinstalled in Liferay 7.0 CE and Liferay DXP instances.
Each Screenlet in Liferay Screens calls one or more of Liferay Portal’s JSON web services, which are enabled by default. The Screenlet reference documentation lists the web services that each Screenlet calls. To use a Screenlet, its web services must be enabled in the portal. It’s possible, however, to disable the web services needed by Screenlets you’re not using. For instructions on this, see the tutorial Portal Configuration of JSON Web Services.
To use CocoaPods to prepare your iOS 9.0 (or above) project for Liferay Screens, follow these steps:
In your project’s root folder, add the following code to the file named
Podfile, or create this file if it doesn’t exist. Be sure to replace
Your Targetwith your target’s name:
source 'https://github.com/CocoaPods/Specs.git' platform :ios, '9.0' use_frameworks! target "Your Target" do pod 'LiferayScreens' end # the rest of your podfile
Note that Liferay Screens and some of its dependencies aren’t compatible with Swift 3.2. If your iOS project is compiled in Swift 3.2, then your
Podfilemust specify Screens and those dependencies for compilation in Swift 4. The
post_installcode in the following
Podfiledoes this. You must therefore use this
Podfileif you want to use Screens in a Swift 3.2 app:
source 'https://github.com/CocoaPods/Specs.git' platform :ios, '9.0' use_frameworks! target "Your Target" do pod 'LiferayScreens' end post_install do |installer| incompatiblePods = [ 'Cosmos', 'CryptoSwift', 'KeychainAccess', 'Liferay-iOS-SDK', 'Liferay-OAuth', 'LiferayScreens', 'Kingfisher' ] installer.pods_project.targets.each do |target| if incompatiblePods.include? target.name target.build_configurations.each do |config| config.build_settings['SWIFT_VERSION'] = '4.0' end end target.build_configurations.each do |config| config.build_settings['CONFIGURATION_BUILD_DIR'] = '$PODS_CONFIGURATION_BUILD_DIR' end end end # the rest of your podfile
On the terminal, navigate to your project’s root folder and run this command:
pod repo update
This ensures you have the latest version of the CocoaPods repository on your machine. Note that this command can take a while to run.
Still in your project’s root folder in the terminal, run this command:
Once this completes, quit Xcode and reopen your project by using the
*.xcworkspacefile in your project’s root folder. From now on, you must use this file to open your project.
Great! To configure your project’s communication with Liferay Portal, you can skip the next section and follow the instructions in the final section.
Configuring communication between Screenlets and Liferay Portal is easy. Liferay
Screens uses a property list (
.plist) file to access your portal instance. It
must include the server’s URL, the portal’s company ID, and the site’s group ID.
liferay-server-context.plist file and specify values required for
communicating with your portal instance. As an example, refer to
The values you need to specify in your
server: Your portal instance’s URL.
version: Your portal instance’s version. Supported values are
70for Liferay 7.0, and
62for Liferay 6.2.
companyId: Your portal instance’s identifier. You can find this value in the Instance ID column of Control Panel → Portal Instances.
groupId: The ID of the default site you want Screens to communicate with. You can find this value in the Site ID field of the site’s Site Administration → Configuration → Site Settings menu.
connectorFactoryClassName: Your Connector’s factory class name. This is optional. If you don’t include it, the
versionvalue is used to determine which factory is the most suitable for that version of Liferay Portal.
Great! Your iOS project is ready for Liferay Screens.