开发者

Make phone call by using UIApplication sharedApplication

I made a button, and link the button to the following openPhone method. But it didn't work. Error m开发者_StackOverflow社区essage shows "Thread 1:Program received signal: "SIGABRT".".

Should I do anything else that I do not know to let it work? Thanks

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


try this:- self.phone is NSString that contain phone number.

    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]];


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

You may also need to remove the + in tel:// . I haven't tested any of this though. The phone number also looks kind of long. Maybe it is just a country thing though.

Also be sure that it is connected in your IB and is specified in your .h

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜