iOS webView抓取改变js的alertView

使用UIWebView在iOS中展示JavaScript Alert对话框
本文详细介绍了如何在iOS应用中利用UIWebView组件,通过JavaScript触发并展示自定义的Alert对话框。文章包括代码实现、实例演示以及相关注意事项,旨在帮助开发者在iOS开发中解决类似需求。

在webView的.h文件中:

@interface UIWebView (JavaScriptAlert) <UIAlertViewDelegate>

 - (void)webView:(UIWebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(CGRect *)frame;

@end

在webView的.m文件中:

@implementation UIWebView (JavaScriptAlert)

- (void)webView:(UIWebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(CGRect *)frame

{

    UIAlertView* customAlert = [[UIAlertView alloc] initWithTitle:@"来自九微应用的提示" message:message delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];

    customAlert.delegate = self;

     [customAlert show];

  //由于类方法继承的是js所以无法声明变量,如果传值可以通过单例

    [InstallStatisticsClass shareInstance].strPay = message;

    NSLog(@"*******%@*********",[InstallStatisticsClass shareInstance].strPay);

}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

{

    if (buttonIndex == 0) {

   //由于类方法继承的是js所以无法进行正常的push和pop,我们可以通过通知的方法进行实现

        [[NSNotificationCenter defaultCenter] postNotificationName:@"Cancellation" object:nil];

    } else {

        NSLog(@",,,,,,,,*******");

    }

    

}

 

转载于:https://www.cnblogs.com/anyezhuixing/p/4092574.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值