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 Liferay DXP 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.3 or newer
- iOS 11 SDK
- CocoaPods 1 or newer
- Liferay Portal 6.2 CE/EE, Liferay CE Portal 7.0/7.1, or Liferay DXP
- Liferay Screens Compatibility Plugin (CE or DXP/EE, depending on your portal edition). This app is preinstalled in Liferay CE Portal 7.0/7.1 CE and Liferay DXP.
Each Screenlet in Liferay Screens calls one or more of Liferay DXP’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 Configuring JSON Web Services. You can also use Service Access Policies for more fine-grained control over accessible 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 or Swift 4.0. If your iOS project is compiled in Swift 3.2 or Swift 4.0, then your
Podfilemust specify Screens and those dependencies for compilation in Swift 4.2. The
post_installcode in the following
Podfiledoes this. You must therefore use this
Podfileif you want to use Screens in a Swift 3.2 or Swift 4.0 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.2' 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 DXP, you can skip the next section and follow the instructions in the final section.
Configuring communication between Screenlets and Liferay DXP is easy. Liferay
Screens uses a property list (
.plist) file to access your Liferay DXP instance.
It must include the server’s URL, the portal’s company ID, and the site’s group
ID. Create a
liferay-server-context.plist file and specify values required for
communicating with your Liferay DXP instance. As an example, refer to
The values you need to specify in your
server: Your Liferay DXP instance’s URL.
version: Your Liferay DXP instance’s version. Supported values are
71for Liferay CE Portal 7.1 or Liferay DXP 7.1,
70for Liferay CE Portal 7.0 or Liferay DXP 7.0, and
62for Liferay Portal 6.2 CE/EE.
companyId: Your Liferay DXP 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 DXP.
Great! Your iOS project is ready for Liferay Screens.