2011-10-05 59 views
2

我做了一个按钮,并将按钮链接到以下openPhone方法。 但它没有奏效。错误信息显示“线程1:程序接收信号:”SIGABRT“。”。使用UIApplication sharedApplication拨打电话

我应该做其他我不知道让它工作的东西吗?由于

-(IBAction)openPhone{ 
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://+886227637978"]]; 
} 
+0

我不认为坠机是因为你的这种方法的发生。你能在控制台上显示消息吗? –

回答

0
-(IBAction)openPhone:(id)sender{ 
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://+886227637978"]]; 
} 

您可能还需要删除+在电话://。我还没有测试过这些。 电话号码也看起来很长。也许这只是一个国家的事情。

另外要确保它是连接在你的IB,并在您的.h

4

试试这个指定: - self.phone是的NSString包含电话号码。

NSString *telephoneString=[self.phone stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; 

    NSMutableString *str1=[[NSMutableString alloc] initWithString:telephoneString]; 
    [str1 setString:[str1 stringByReplacingOccurrencesOfString:@"(" withString:@""]]; 
    [str1 setString:[str1 stringByReplacingOccurrencesOfString:@")" withString:@""]]; 
    [str1 setString:[str1 stringByReplacingOccurrencesOfString:@"-" withString:@""]]; 
    [str1 setString:[str1 stringByReplacingOccurrencesOfString:@" " withString:@""]]; 
    telephoneString = [@"tel://" stringByAppendingString:str1]; 
    [str1 release]; 
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:telephoneString]];