0

我阅读了一些关于如何在 iPhone 上以编程方式拨打电话的参考资料,因此我将其放入我的代码中:

UIApplication *app = [UIApplication sharedApplication];
NSString *urlString = [NSString stringWithFormat:@"tel:0225225657"];
NSURL *url = [NSURL URLWithString:urlString];
[app openURL:url];

那是对的吗?如果是,我怎么知道我的应用程序在模拟器中运行时拨打了那个号码?

4

2 回答 2

2

您的代码正在运行。你只是不能在模拟器中使用它。我的理由是这样的:

UIApplication *app = [UIApplication sharedApplication];
NSString *urlString = [NSString stringWithFormat:@"http://www.google.com"];
NSURL *url = [NSURL URLWithString:urlString];
[app openURL:url];

这是您的代码,但带有http://www.google.com而不是您的电话 URL。它打开 Safari 并转到 Google。只需在您的设备上进行测试,它应该可以工作。

于 2010-08-25T06:02:27.523 回答
0

那不应该是:

NSString *urlString = [NSString stringWithFormat:@"tel://0225225657"];

??

于 2010-08-25T06:01:38.680 回答