使用UIWebview调用如何知道点击了UIAlertView的哪个按钮Index
How can I know which button Index of UIAlertView is clicked when I use UIWebview to make a call
我能够生成警报,允许用户使用 UIWebView
和以下代码拨打电话:
UIWebView *webV= [[UIWebView alloc] init];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"tel:1834563578"]];
[webV loadRequest:request];
但是,当我使用 UIWebView 进行调用时,系统会出现提示。我想知道用户选择了哪个按钮索引。我不知道如何检索用户在警报中选择的选项的索引。
Use The following Code.
UIAlertAction* cameraButton = [UIAlertAction
actionWithTitle:@"Button1"
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction * action) {
// do somethingg
}];
UIAlertAction *cancelButton = [UIAlertAction
actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction * action) {
//do nothing
}];
[alert addAction:cameraButton];
[alert addAction:cancelButton];
[self presentViewController:alert animated:YES completion:nil];
仅供 iOS10+.
您可以在 UIWebViewDelegate
中检测到呼叫:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if ([request.URL.absoluteString hasPrefix:@"tel:"]) {
// make a call
// this method is available in iOS10
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]
options:nil
completionHandler:^(BOOL success) {
// if success is NO, user tap cancel button, or other
NSLog(@"%d", success);
}];
return NO; // the default view will not show
}
return YES;
}
设置UIWebView
:
UIWebView *webV= [[UIWebView alloc] init];
webV.delegate = self;
NSURLRequest *request = [NSURLRequest requestWithURL: [NSURL URLWithString:@"tel:1834563578"]];
[webV loadRequest: request];
通过这个,你会知道点击了哪个按钮取决于
在 success
在 completionHandler
.
我能够生成警报,允许用户使用 UIWebView
和以下代码拨打电话:
UIWebView *webV= [[UIWebView alloc] init];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"tel:1834563578"]];
[webV loadRequest:request];
但是,当我使用 UIWebView 进行调用时,系统会出现提示。我想知道用户选择了哪个按钮索引。我不知道如何检索用户在警报中选择的选项的索引。
Use The following Code.
UIAlertAction* cameraButton = [UIAlertAction
actionWithTitle:@"Button1"
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction * action) {
// do somethingg
}];
UIAlertAction *cancelButton = [UIAlertAction
actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction * action) {
//do nothing
}];
[alert addAction:cameraButton];
[alert addAction:cancelButton];
[self presentViewController:alert animated:YES completion:nil];
仅供 iOS10+.
您可以在 UIWebViewDelegate
中检测到呼叫:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if ([request.URL.absoluteString hasPrefix:@"tel:"]) {
// make a call
// this method is available in iOS10
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]
options:nil
completionHandler:^(BOOL success) {
// if success is NO, user tap cancel button, or other
NSLog(@"%d", success);
}];
return NO; // the default view will not show
}
return YES;
}
设置UIWebView
:
UIWebView *webV= [[UIWebView alloc] init];
webV.delegate = self;
NSURLRequest *request = [NSURLRequest requestWithURL: [NSURL URLWithString:@"tel:1834563578"]];
[webV loadRequest: request];
通过这个,你会知道点击了哪个按钮取决于
在 success
在 completionHandler
.