Reviewing JSAPI integration
This application uses JSAPI to display BIRT visualizations in embedded web views. A web view can render CSS, HTML, and JavaScript in the native code of the mobile application. JSAPI communicates with the iHub server using the authentication ID from the REST API login request. Native code injects values into JSAPI requests before they are sent. The JSAPI then downloads and displays interactive BIRT content about the selected location using a bookmarked chart and a full page report. Bookmarks are a method to identify content in a BIRT report.
This example uses the following Objective-C methods to communicate with the HTML content in a UIWebView:
*Replace string values in the embedded HTML file before loading the HTML file into the web view. This replacement uses the NSString’s stringByReplacingOccurrencesOfString function to find string values in the jsapi.html file and replace those values with the current values, such as the server URL, and the username and password.
*Call the init JavaScript function embedded in the web view and pass the values required to display the BIRT content. This call uses the UIWebView’s stringByEvaluatingJavaScriptFromString function to call the JavaScript function.
The ReportView folder of the Xcode project contains the Objective-C files that define the UIWebView. The BIRTWebViewController.m file organizes the values necessary to identify and find a report file, the data to be shown in that file, and how to load the JSAPI library from the current iHub server. These values are put into an NSString in the JSON format. The BIRTWebViewController.m file then loads the jsapi.html file into a UIWebView and sends the JSON values to the init function in the jsapi.html file.
Communication to the UIWebView occurs in one direction. The Objective-C code can send parameters and values to the content displayed in a UIWebView. The content in the UIWebView does not communicate back to Objective-C code in this application.
For more information about embedding BIRT visualizations in HTML see Integrating Applications into BIRT iHub.