passing objective c variable to javascript in ios

By : djk
Source: Stackoverflow.com
Question!

How to pass a ObjectiveC string Variable to a javascript function? I have just started with javascript.. so plz 4give my ignorance...

By : djk


Answers

In Objective-C

NSString *str  = @"hi ya";   
[self.webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"myFunc('%@')",str]];

Now call this function in the js file:

function myFunc(str)
{
   alert(str);
}

These steps should work.

By : Saurabh


This video can help you solving your question :)
By: admin