Updating JavaScript in a web view
Values required to load the Actuate JavaScript API from the server are written to the embedded file jsapi.html before that HTML file is loaded in a UIWebView. The UIWebView then loads the embedded jsapi.html file, as shown in the following code:
[self loadHTML:@"jsapi.html"];
...
- (void) loadHTML:(NSString*) pageName
{
NSRange range = [pageName rangeOfString:@"."];
if (range.length > 0)
{
NSString *fileExt = [pageName substringFromIndex:range.location+1];
NSString *fileName = [pageName substringToIndex:range.location];
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:fileName ofType:fileExt inDirectory:@""]];
if (url != nil)
{
NSError *error;
NSString *pageContent = [NSString stringWithContentsOfURL:url
encoding:NSASCIIStringEncoding
error:&error];
NSString *finalContent = [pageContent stringByReplacingOccurrencesOfString:@"jsapiUrl" withString:[NSString stringWithFormat:@"%@%@", IHUB_SERVER_URL, @"iportal/jsapi"]];
FinalContent = [finalContent stringByReplacingOccurrencesOfString:@"{uName}" withString:[NSString stringWithFormat:@"%s%@%s", "'", self.chartData.userName, "'"]];
if (self.chartData.password == nil) {
finalContent = [finalContent stringByReplacingOccurrencesOfString:@"{pwd}" withString:self.chartData.password];
} else {
finalContent = [finalContent stringByReplacingOccurrencesOfString:@"{pwd}" withString:[NSString stringWithFormat:@"%s%@%s", "'", self.chartData.password, "'"]];
}
[self.webView loadHTMLString:finalContent baseURL:url];
}
}
}
Next, an NSString is built with the values required to display the BIRT content, such as the BIRT report name, the name of the selected location, and the viewing size of the BIRT content, as shown in the following code:
NSString *file = [NSString stringWithFormat:@"%@%@",REPORT_FOLDER, fileName];
 
jsData[@"report"] = file;
if (islandscape) {
jsData[@"width"] = [NSString stringWithFormat:@"%f", 1024.0];
jsData[@"height"] =[NSString stringWithFormat:@"%f", 768.0];
} else {
jsData[@"width"] = [NSString stringWithFormat:@"%f", 768.0];
jsData[@"height"] =[NSString stringWithFormat:@"%f", 960.0];
}
 
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsData optionerror:&jsonError];
 
NSString *jsonStr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
See the source code for the complete example.