我想在用户进入前台时自动刷新UIwebview。 这是我想在我的html文件中运行的javascript函数:
<script>
function testfunctionforios() {
refreshfunction();
}
</script>
AppDelegate.m
- (void)applicationDidBecomeActive:(UIApplication *)application {
[self connectToFcm];
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
NSLog(@"in applicationdidbecomeactive");
[self.viewWeb stringByEvaluatingJavaScriptFromString:@"testfunctionforios()"];
}
当我使用applicationDidBecomeActive时,javascript函数未成功调用,但我看到了NSLog消息!
当我尝试使用webViewDidFinishLoad时 ViewController.m
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
if ( webView == self.viewWeb )
{
NSLog(@"calling testfunction");
[self.viewWeb stringByEvaluatingJavaScriptFromString:@"testfunctionforios()"];
}
}
调用该函数。
提前致谢!