iOS打電話功能

fdwm 9年前發布 | 8K 次閱讀 Objective-C IOS

//第一種打電話的方式

- (IBAction)firstCall:(id)sender {

    NSString *phone = @"18749627117";

    if (phone != nil) {

        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",phone]]];//使用這個方法,打電話結束后會進入聯系人列表

        //[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"telprompt://%@",phone]]];//使用這種方法在撥打電話前會先彈出框,詢問是否打電話,然后打完電話之后回到主程序中,有人說這種方法可能不合法,無法通過審核

    }

}

//第二種打電話的方式

- (IBAction)secondCall:(id)sender {

    NSString *str = [NSString stringWithFormat:@"tel:%@",@"18749627117"];

    UIWebView *callWebView = [[UIWebView alloc]init];

    [callWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];

    [self.view addSubview:callWebView];//也可以不加到頁面上

}


 本文由用戶 fdwm 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!