Adding Custom Interactors to iOS Screenlets

Interactors are Screenlet components that implement server communication for a specific use case. For example, the Login Screenlet’s interactor calls the Liferay Mobile SDK service that authenticates a user to the portal. Similarly, the interactor for the Add Bookmark Screenlet calls the Liferay Mobile SDK service that adds a bookmark to the Bookmarks portlet.

That’s all fine and well, but what if you want to customize a Screenlet’s server call? What if you want to use a different back-end with a Screenlet? No problem! You can implement a custom interactor for the Screenlet. You can plug in a different interactor that makes its server call by using custom logic or network code. To do this, you must implement the current interactor’s interface and then pass it to the Screenlet you want to override. You should do this inside your app’s code.

In this tutorial, you’ll see an example interactor that overrides the Login Screenlet to always log in the same user, without a password.

Implementing a Custom Interactor

  1. Implement your custom interactor. You must inherit ServerConnectorInteractor, as shown here:

     class LoginCustomInteractor: ServerConnectorInteractor {
    
         override func createConnector() -> ServerConnector? {
    
             ...
    
             return connector
         }
    
     }
    
  2. Implement the optional protocol that receives a customInteractorForAction, and return your own interactor:

     func screenlet(screenlet: BaseScreenlet, 
             customInteractorForAction: String, 
             withSender: AnyObject?) -> Interactor? {
    
         return LoginCustomInteractor()
     }
    

Great! Now you know how to implement custom interactors for iOS Screenlets.

Architecture of Liferay Screens for iOS

Creating iOS Screenlets

« Accessing the Liferay Session in iOSRendering Web Content in Your iOS App »
¿Fue útil este artículo?
Usuarios a los que les pareció útil: 0 de 0