0

我已经像这样以编程方式完成了调用。

NSString *phoneNumber = [[self.arrCategory objectAtIndex:0]objectForKey:@"MOBILE"]; 

NSString *phoneURLString = [NSString stringWithFormat:@"tel:%@", phoneNumber];
NSURL *phoneURL = [NSURL URLWithString:phoneURLString];
[[UIApplication sharedApplication] openURL:phoneURL];

但我不能从 iphone 打电话。问题是什么?

4

4 回答 4

2

现在只需用您的代码替换此代码,可能是因为在 phoneno 或 phone url 中使用了空格,所以它没有被调用..使用此代码..

    NSString *phoneNumber = [[self.arrCategory objectAtIndex:0]objectForKey:@"MOBILE"];
    NSArray* telComponents = [phoneNumber componentsSeparatedByCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
    phoneNumber = [telComponents componentsJoinedByString: @""];

    NSString* urlString = [NSString stringWithFormat: @"tel:%@", phoneNumber];
    NSURL* telURL = [NSURL URLWithString: urlString];

    if ( [[UIApplication sharedApplication] canOpenURL: telURL] )
    {
        [[UIApplication sharedApplication] openURL: telURL];
    }
    else
    {
        UIAlertView* alert = [[UIAlertView alloc] initWithTitle: NSLocalizedString( @"Dialer Error", @"" ) 
                                                        message: [NSString stringWithFormat: NSLocalizedString( @"There was a problem dialing %@.", @"" ), phoneNumber] 
                                                       delegate: nil 
                                              cancelButtonTitle: NSLocalizedString( @"OK", @"" ) 
                                              otherButtonTitles: nil];
        [alert show];
        [alert release];
    }

更新:

试试这个也...

#import "RegexKitLite.h"

NSString * number = @"(555) 555-555 Office";
NSString * strippedNumber = [number stringByReplacingOccurrencesOfRegex:@"[^0-9]" withString:@""];

从 iphone sdk 查看此代码的链接 - 从字符串中删除除数字 0-9 之外的所有字符

于 2013-01-03T10:21:42.377 回答
1

试试这个并检查:

 NSString *phoneNumber = [[self.arrCategory objectAtIndex:0]objectForKey:@"MOBILE"]; 
    NSString *phoneURLString = [@"tel://" stringByAppendingString:phoneNumber];
    NSURL *phoneURL = [NSURL URLWithString:phoneURLString];
    [[UIApplication sharedApplication] openURL:phoneURL];
于 2013-01-03T10:21:30.263 回答
0

请从这里尝试我的示例代码,

http://yuvarajmanickam.wordpress.com/2012/03/03/make-a-call-from-iphone-app/

请使用您的电话号码而不是 phoneNumber 字符串。请让我知道它是否对您有用。我希望它会帮助你。谢谢。

于 2013-01-03T10:30:13.003 回答
0

尝试这个:

UIWebView *callWebview = [[UIWebView alloc] initWithFrame:CGRectMake(0,0, 0, 0)];
[self.view addSubview:callWebview];
NSString *phoneNumber = [[self.arrCategory objectAtIndex:0]objectForKey:@"MOBILE"]; 
    NSString *phoneWithoutSpaces = [[NSString stringWithFormat:@"tel://%@", phoneNumber] stringByReplacingOccurrencesOfString:@" " withString:@""];
NSURL *telURL = [NSURL URLWithString:phoneWithoutSpaces];
[callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];

它对我有用。

于 2013-01-03T11:23:23.940 回答