Preparing iOS Projects for Liferay Screens

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.

Requirements

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:

Securing JSON Web Services

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.

Configuring Your Project with CocoaPods

To use CocoaPods to prepare your iOS 9.0 (or above) project for Liferay Screens, follow these steps:

  1. 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 Target with 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 Podfile must specify Screens and those dependencies for compilation in Swift 4. The post_install code in the following Podfile does this. You must therefore use this Podfile if 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 
    
  2. 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.

  3. Still in your project’s root folder in the terminal, run this command:

    pod install
    

    Once this completes, quit Xcode and reopen your project by using the *.xcworkspace file 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 with Liferay

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. Create a liferay-server-context.plist file and specify values required for communicating with your portal instance. As an example, refer to liferay-server-context-sample.plist.

Figure 1: Heres a property list file, called liferay-context.plist.

Figure 1: Here's a property list file, called `liferay-context.plist`.

The values you need to specify in your liferay-server-context.plist are:

  • server: Your portal instance’s URL.
  • version: Your portal instance’s version. Supported values are 70 for Liferay 7.0, and 62 for Liferay 6.2.
  • companyId: Your portal instance’s identifier. You can find this value in the Instance ID column of Control PanelPortal 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 AdministrationConfigurationSite Settings menu.
  • connectorFactoryClassName: Your Connector’s factory class name. This is optional. If you don’t include it, the version value 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.

Using Screenlets in iOS Apps

Using Themes in iOS Screenlets

Preparing Android Projects for Liferay Screens

« Introduction to iOS Apps with Liferay ScreensUsing Screenlets in iOS Apps »
Este artigo foi útil?
Utilizadores que acharam útil: 0 de 0