How to use 3rd party generated NFIs in Iris for iOS platform
Pre-requisite
- Have a successfully generated NFI.(3rd party NFI generation has been published at Generate 3rd party NFIs for iOS platform)
Import generated NFI to Iris
- Open VoltMX Iris.
- In the top Menu bar, Go to Edit-> Manage Native Function API(s)
- To add generated NFI click on Import and select generated NFI to import and click Open.
- On successful import NFI screen would like below:
How to use NFI methods in Iris
Method | Description |
---|---|
objc.import(<native_class_name>) | Imports native class to javascript |
objc.newClass | Creates a new objective-c class and exposes objective-c class to javascript. |
Arguments for objc.newClass:
- native_class_name
- base_class_name
- interface_name
- interface_name_to_override
Javascript Snippets
- To import a new native class into Iris javascript.
LoggerClass = objc.import("Logger"); //Logger is native class here.
- To create a new objective-c sub class in javascript
myNewClass: objc.newClass('MyNewClass', 'NSObject', ['UITextFieldDelegate'], {
onNativeBtnClick: function(){
alert("native button on click");
}
}
- Import class snippet
- Create new sub-class snippet
Adding native UIButton to Iris Application
- Drag and drop Native Container widget of Iris on to a Form.
- On OnCreated action of Native container we can add code snippet
to get UIButton.
UIButton Snippet for OnCreated Action
- import UIButton class using objc.import
- Add UIButton related properties and add to native container view as a subview.
ViewController Presentation
- If you want to present your own viewController, you have to present it as a modal View Controller on top of the existing root view controller.*
//To display vc (new UI viewController)
UIApplication.sharedApplication().keyWindow.rootViewController.
presentViewControllerAnimatedCompletion(vc, true, null);
- Dismissing of view controller
//To dismiss the new UIviewController
UIApplication.sharedApplication().keyWindow.rootViewController.dismissViewControllerAnimatedCompletion(true, null);
- It is mandatory to maintain camel case when using methods that have multiple parameters and all parameters can be given at once after the method name.
Documentation Links
- Introducing the Native Function API - HCL Volt MX Documentation V9.2
- Add or Import Native Function APIs - HCL Volt MX Documentation V9.2
- iOS Quick Start Guide - HCL Volt MX Documentation V9.2
- Using the Native Function API for iOS - HCL Volt MX Documentation V9.2
NFI Examples for iOS