如何从 iphone 应用程序查询调用 safari 中的 weblink

发布于 2024-12-16 12:58:39 字数 1012 浏览 1 评论 0原文

我正在解析 xml 文件以获取电话号码值(aMarker.web= weblink)。其中标记是我在解析器控制器中获取的 xml 文件中的属性。我可以使用以下方法在按钮标题上设置此 webLink 字符串,

        [w_Bcard setTitle:[NSString stringWithFormat:@"%@",aMarker.web] forState:UIControlStateNormal];

但通过点击按钮我无法拨打该号码。请参阅我的代码

 - (IBAction)weblink_BcardVeiw
   {

NSIndexPath *selectedIndexPath = [self.tableView indexPathForSelectedRow];

marker *aMarker = (marker *)[appDelegate.markers  objectAtIndex:selectedIndexPath.row];
 for (int selectedIndexPath = 0; selectedIndexPath < [appDelegate.markers count];  selectedIndexPath++)
 {
    NSString *utfString = [NSString stringWithFormat:@"%@",aMarker.web];        
    NSURL *url = [NSURL URLWithString:utfString];

    [[UIApplication sharedApplication] openURL:url];
    NSLog(@"%@",url);
   }
[self.tableView deselectRowAtIndexPath:selectedIndexPath animated:YES];

通过 NSloging m 获取相应的 url,但无法在 safari 中打开此 url。我应该在哪里更正上面的代码??? 我还想通过传递动态字符串 aMarker.email 来调用邮件应用程序。您也可以建议该代码吗?

I am parsing xml file to get phone number values (aMarker.web= weblink). Where marker is attributes in xml file which I am fetching in my parser controller. I am able to set this webLink string on Button title by using

        [w_Bcard setTitle:[NSString stringWithFormat:@"%@",aMarker.web] forState:UIControlStateNormal];

But by tapping button I am not able to call the number. See my code

 - (IBAction)weblink_BcardVeiw
   {

NSIndexPath *selectedIndexPath = [self.tableView indexPathForSelectedRow];

marker *aMarker = (marker *)[appDelegate.markers  objectAtIndex:selectedIndexPath.row];
 for (int selectedIndexPath = 0; selectedIndexPath < [appDelegate.markers count];  selectedIndexPath++)
 {
    NSString *utfString = [NSString stringWithFormat:@"%@",aMarker.web];        
    NSURL *url = [NSURL URLWithString:utfString];

    [[UIApplication sharedApplication] openURL:url];
    NSLog(@"%@",url);
   }
[self.tableView deselectRowAtIndexPath:selectedIndexPath animated:YES];

By NSloging m getting respective url but not able to open this url in safari. Where should I correct the above code???
I also want to call mail application by passing dynamic string aMarker.email. Can you suggest that code also.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

氛圍 2024-12-23 12:58:39

您将使用数据检测器。例如,您可能会这样做:

- (void)dataDetectorPassInRange:(NSRange)range
{
    if (![self dataDetectorTypes])
            return;

    NSError* error = NULL;
    NSDataDetector* detector = [NSDataDetector dataDetectorWithTypes:self.dataDetectorTypes error:&error];
    NSAssert(error == nil, @"Problem creating the link detector: %@", [error localizedDescription]);
    NSString* string = [self yourStringStore];

    [detector enumerateMatchesInString:string options:0 range:range usingBlock:^(NSTextCheckingResult* match, NSMatchingFlags flags, BOOL* stop){
            NSRange matchRange = [match range];
            if([match resultType] == NSTextCheckingTypePhoneNumber)
            {
                    NSString* phoneNumber = [match phoneNumber];
                    NSURL* phoneURL = [NSURL URLWithString:phoneNumber];
                    [[UIApplication sharedApplication] openURL:phoneURL];
            }
    }];
}

我在某些代码中做了类似的事情,我创建了一个替换 UITextView,它可以处理属性文本(样式)并检测电话号码、链接和地址等内容。基本上你想要的是数据检测器。

You would use a data detector. For instance, you might do something like this:

- (void)dataDetectorPassInRange:(NSRange)range
{
    if (![self dataDetectorTypes])
            return;

    NSError* error = NULL;
    NSDataDetector* detector = [NSDataDetector dataDetectorWithTypes:self.dataDetectorTypes error:&error];
    NSAssert(error == nil, @"Problem creating the link detector: %@", [error localizedDescription]);
    NSString* string = [self yourStringStore];

    [detector enumerateMatchesInString:string options:0 range:range usingBlock:^(NSTextCheckingResult* match, NSMatchingFlags flags, BOOL* stop){
            NSRange matchRange = [match range];
            if([match resultType] == NSTextCheckingTypePhoneNumber)
            {
                    NSString* phoneNumber = [match phoneNumber];
                    NSURL* phoneURL = [NSURL URLWithString:phoneNumber];
                    [[UIApplication sharedApplication] openURL:phoneURL];
            }
    }];
}

I do something like this in some code where I create a replacement UITextView which can handle attributed text (styled) and detect things like phone numbers, links and addresses. Basically what you want are data detectors.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文