【问题标题】:Objective-C open links in Safari and Alert DialogObjective-C 在 Safari 和警报对话框中打开链接
【发布时间】:2015-08-09 01:41:01
【问题描述】:

我有一个 UIwebView,它在网页中有一些链接。我想要一个特定的链接来打开一个警报模式,如图像 #1 中所示

另外,如何使用下面的代码来制作这样的东西 - (IMAGE #1) http://screenshot.it.sftcdn.net/blog/it/2014/01/Block-user-03-Tasto-Block-378x568.png in objective-c

- (IBAction)showAlert:(id)sender
{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Open In..."
                 message:@"Which app would you like to open?"
          preferredStyle:UIAlertControllerStyleActionSheet];

    UIAlertAction *mapsAction = [UIAlertAction actionWithTitle:@"Maps"
            style:UIAlertActionStyleDefault
          handler:^(UIAlertAction *action) {
              if (![self openURLForString:@"maps://"]) {
                  NSLog(@"Couldn't Open Maps");
              }
          }];
    UIAlertAction *youtubeAction = [UIAlertAction actionWithTitle:@"YouTube"
            style:UIAlertActionStyleDefault
          handler:^(UIAlertAction *action) {
              if (![self openURLForString:@"http://www.youtube.com/watch?v=dQw4w9WgXcQ"]) {
                  NSLog(@"Couldn't Open YouTube");
              }
          }];
    UIAlertAction *messagesAction = [UIAlertAction actionWithTitle:@"Messages"
            style:UIAlertActionStyleDefault
          handler:^(UIAlertAction *action) {
              if (![self openURLForString:@"sms://"]) {
                  NSLog(@"Couldn't Open Messages");
              }
          }];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel"
           style:UIAlertActionStyleCancel
         handler:nil];

    [alertController addAction:mapsAction];
    [alertController addAction:youtubeAction];
    [alertController addAction:messagesAction];
    [alertController addAction:cancelAction];

    [self presentViewController:alertController animated:YES completion:nil];
}

- (BOOL)openURLForString:(NSString *)urlString {
    NSURL *url = [NSURL URLWithString:urlString];
    if ([[UIApplication sharedApplication] canOpenURL:url]) {
        [[UIApplication sharedApplication] openURL:url];
        return YES;
    }
    return NO;
}

“报告不当”是在第二个 UIwebView 中打开的链接,该链接在父 webview 上方打开,“共享”在 Safari 中打开。 (忽略“复制链接/网址”)

【问题讨论】:

  • 不清楚您在问什么...您是在问如何执行模态视图控制器转换以呈现新的 Web 视图?
  • @stuart #1) 我希望 uiwebview 网页中的某个链接打开警报模式,如图像 #1 #2) 其中图像 #1 中的“报告不当”是一个链接在第二个 UIwebView 中打开,该 UIwebView 在父 webview 上打开,并且“共享”在 Safari 中打开。 (忽略“复制链接/URL”)
  • 请在下面查看我的答案,如果它有效,请告诉我。谢谢。

标签: ios objective-c


【解决方案1】:

您需要首先为 Web 视图协议注册视图控制器。

然后在您的视图控制器中实现 Web 视图的委托方法确实开始加载并检查被调用的 URL 并使用 if else 检查相应地执行您的任务

这是委托参考:

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIWebViewDelegate_Protocol/

通过我的手机应答。请原谅语法。

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-06
    • 1970-01-01
    • 2018-01-23
    • 1970-01-01
    • 2020-07-25
    • 1970-01-01
    相关资源
    最近更新 更多