iOS UIWebView Javascript - insert data -receive callbacks?

后端 未结 3 1874

I have a webpage. I have a javascript file that does a whole lot of stuff. In the app I have an NSString with some crucial data that needs to be processed in the javascrip

3条回答
  •  难免孤独
    2020-12-07 20:02

    Hi we can send the data from objective c to javascript and can callback from javascript easily

    Objective-C --> javaScript

    In Objective-C class

    NSData *locationCountData = [NSJSONSerialization dataWithJSONObject:locationCount   options:NSJSONWritingPrettyPrinted error:nil];
    NSString *locationCountString = [[NSString alloc] initWithData:locationCountData encoding:NSUTF8StringEncoding];
    
    NSData *locationCountData = [NSJSONSerialization dataWithJSONObject:locationCount options:NSJSONWritingPrettyPrinted error:nil];
    NSString *locationCountString = [[NSString alloc] initWithData:locationCountData encoding:NSUTF8StringEncoding];
    
    NSString *str = [NSString   stringWithFormat:@"testFunction(%@,%@)",locationCountString, locationsListString];
    [self.myWebView stringByEvaluatingJavaScriptFromString: str];
    

    in JavaScript file

    
    

提交回复
热议问题