2011-11-17 20 views
0

我解析xml文件以獲取電話號碼值(aMarker.web = weblink)。其中marker是我在解析器控制器中獲取的xml文件中的屬性。我能夠通過使用如何從iphone應用程序查詢中在safari中調用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獲取相應的網址,但無法在safari中打開此網址。我應該在哪裏糾正上面的代碼? 我也想通過傳遞動態字符串aMarker.email來調用郵件應用程序。你也可以提供代碼嗎?

回答

0

您將使用數據檢測器。例如,你可能會做這樣的事:

- (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,它可以處理屬性文本(樣式)和檢測如電話號碼,鏈接和地址的事情。基本上你想要的是數據檢測器。

+0

我剛剛能夠通過應用程序打電話。我沒有使用dattdetector的東西...看到http://stackoverflow.com/questions/8165796/how-to-make-call-from-iphone-app-on-xml-parser-value/8166595#8166595 –

相關問題