iOS 撥打電話功能

方法一:合法的,並且有彈框是否撥號
在.h文件中先聲明一個UIWebView 的對象 phoneCallWebView(注意:phoneCallWebView必須是全局變量

而後在.m文件中添加以下代碼;
 

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath {web

NSString *phoneNum = @"12301";// 電話號碼
    
    NSURL *phoneURL = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",phoneNum]];  
    
    if ( !phoneCallWebView ) {          
        
        phoneCallWebView = [[UIWebView alloc] initWithFrame:CGRectZero];// 這個webView只是一個後臺的容易 不須要add到頁面上來  效果跟方法二同樣 可是這個方法是合法的
        
    } 
    [phoneCallWebView loadRequest:[NSURLRequest requestWithURL:phoneURL]];
}

若是在方法裏定義phoneCallWebView,phoneCallWebView就是局部變量,在方法外就失效了不執行撥打電話功能了。


方法二 撥打完電話回不到原來的應用,會停留在通信錄裏,並且是直接撥打,不彈出提示

NSMutableString *str=[[NSMutableString alloc] initWithFormat:@"tel:%@",@"186xxxx6979"];spa

// NSLog(@"str======%@",str);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
orm

相關文章
相關標籤/搜索