Preparing Xamarin Projects for Liferay Screens

To use Liferay Screens with Xamarin, you must install Screens in your Xamarin project. You must then configure your project to communicate with your Liferay DXP instance. Note that Liferay Screens for Xamarin is released as a NuGet package hosted in NuGet.org.

Requirements and Example Projects

Liferay Screens for Xamarin includes the bindings necessary to use all Screenlets included with Screens. The following software is required:

Also note that if you get confused or stuck while using Screens for Xamarin, the official Liferay Screens repository contains two sample Xamarin projects that you can reference:

  • Showcase-Android: An example app for Xamarin.Android containing all the currently available Screenlets.

  • Showcase-iOS: An example app for Xamarin.iOS containing all the currently available Screenlets.

Securing JSON Web Services

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 for Android and iOS 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.

Install Liferay Screens in Xamarin Solutions

Follow these steps to install Liferay Screens in your Xamarin project:

  1. Open your project in Visual Studio.

  2. Right click your project’s Packages folder and then select Add packages….

  3. Look for LiferayScreens and install the latest version.

  4. Accept the license agreements for any dependencies. These are necessary to use Liferay Screens in Xamarin.

  5. Check your configuration one of these ways:

    • Rebuild and execute your project, and import a Liferay Screens path (e.g., Com.Liferay.Mobile.Screens.Auth.Login).
    • In your project, select ReferencesFrom Packages and look for the LiferayScreens* file. Open that file in the Assembly Browser. You should then see all the available Liferay Screens files.

Next, you’ll set up communication with Liferay DXP.

Configuring Communication with Liferay DXP

Before using Liferay Screens, you must configure your project to communicate with your Liferay DXP instance. To do this, you must provide your project with the following information:

  • Your Liferay DXP instance’s ID.
  • The ID of the Liferay DXP site your app needs to communicate with.
  • Your Liferay DXP instance’s version.
  • Any other information required by specific Screenlets.

Fortunately, this is straightforward. Do the following in your Xamarin projects:

  • For Xamarin.Android, create a new file called server_context.xml in the Resources/values folder. Add the following code to this file:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
    
        <!-- Change these values for your portal installation -->
        <string name="liferay_server">http://10.0.2.2:8080</string>
    
        <integer name="liferay_company_id">20116</integer>
        <integer name="liferay_group_id">20143</integer>
    
        <integer name="liferay_portal_version">70</integer>
    
    </resources>
    
  • For Xamarin.iOS, create a new file called liferay-server-context.plist in the Resources folder. Add the following code to this file:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
        <key>server</key>
        <string>http://localhost:8080</string>
        <key>version</key>
        <integer>70</integer>
        <key>companyId</key>
        <real>20116</real>
        <key>groupId</key>
        <real>20143</real>
    </dict>
    </plist>
    

Make sure to change these values to match those of your Liferay DXP instance. The server address http://10.0.2.2:8080 is suitable for testing with Android Studio’s emulator, because it corresponds to localhost:8080 through the emulator. If you’re using the Genymotion emulator, you should, however, use 192.168.56.1 instead of localhost.

The liferay_company_id and companyId values are your Liferay DXP instance’s ID. You can find this in your Liferay DXP instance at Control PanelConfigurationVirtual Instances. The instance’s ID is in the Instance ID column.

The liferay_group_id and groupId values are the ID of the site your app needs to communicate with. To find this value, first go to the site in your Liferay DXP instance that you want your app to communicate with. In the Site Administration menu, select ConfigurationSite Settings. The site ID is listed at the top of the General tab.

The liferay_portal_version and version value 70 tells Screens that it’s communicating with a Liferay CE Portal 7.0 or Liferay DXP 7.0 instance. Here are the supported values and the portal versions they correspond to:

  • 71: Liferay CE Portal 7.1 or Liferay DXP 7.1
  • 70: Liferay CE Portal 7.0 or Liferay DXP 7.0
  • 62: Liferay Portal 6.2 CE/EE

You can also configure Screenlet properties in server_context.xml and liferay-server-context.plist. The example server_context.xml properties listed below, liferay_recordset_id and liferay_recordset_fields, enable DDL Form Screenlet and DDL List Screenlet to interact with a Liferay DXP instance’s DDLs:

<!-- Change these values for your portal installation -->

<integer name="liferay_recordset_id">20935</integer>
<string name="liferay_recordset_fields">Title</string>

For additional examples of these files, see the Showcase-Android and Showcase-iOS sample projects.

Super! Your Xamarin projects are ready for Liferay Screens.

Using Screenlets in Xamarin Apps

Using Views in Xamarin.Android

Using Themes in Xamarin.iOS

Creating Xamarin Views and Themes

Liferay Screens for Xamarin Troubleshooting and FAQs

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