I have a button inside a web view.
When the button is clicked, I would like to add the item to my native code array.
Then, when it's pressed again, I would like to remove the item in the array.
My question is: What's missing in the logic? Neither userContentController or decidePolicyForNavigationAction is called when the button is pressed.
The JavaScript Code
<script type = "text/javascript">
function someFunction(id) {
if(id = true) {
document.getELementById("someid").innerText = " some title state 1"
} else {
document.getELementById(someid).innerText = " some title state 2"
}
}
<script>
The Html Button
<button class=someclass id="someid" onclick= "Some.listCallBack()">Add List</button>
The Objective C code
TableViewCell.h
@interface TableViewCell : UITableViewCell <WKNavigationDelegate, WKScriptMessageHandler>
@property (nonatomic,strong) IBOutlet WKWebView *webView;
TableViewCell.m
- (void)awakeFromNib {
[[[self.webView configuration] userContentController]addScriptMessageHandler:selfname:@"someid"];
}
- (void)userContentController:(nonnull WKUserContentController *)userContentController
didReceiveScriptMessage:(nonnull WKScriptMessage *)message {
// i will handle event here
}
Some.listCallback()? Whatever is missing (or isn’t missing) seems to be in there.