2014-09-11 08:12:52 MHTios 阅读数 1131
#pragma mark - AddressBookCellDelegate
- (void)didClickCallButtonAtIndexPath:(NSIndexPath *)indexPath
{
    //可以实现拨打前弹出提示。并且拨打完以后会回到原来的应用
        NSDictionary *dic = self.names[self.titles[indexPath.section]][indexPath.row];
	NSString *phone = dic[@"phoneNumber"];
	NSString *str=[NSString stringWithFormat:@"tel:%@", phone];
	UIWebView *callWebview = [[UIWebView alloc] init];
	[callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
	[self.view addSubview:callWebview];
	[callWebview release];
}

2014-12-17 13:45:22 woaifen3344 阅读数 1005

自己写了个调起打电话的类,只需要修改一点点就可以直接使用:

//
//  HYBPhoneCallHelper.h
//  XiaoYaoUser
//
//  Created by 黄仪标 on 14/12/16.
//  Copyright (c) 2014年 xiaoyaor. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface HYBPhoneCallHelper : NSObject

// 调用默认客服电话
+ (void)call;
+ (void)callWithPhone:(NSString *)phone;
+ (void)callInController:(UIViewController *)controller;
+ (void)callInController:(UIViewController *)controller WithPhone:(NSString *)phone;

@end

#import "HYBPhoneCallHelper.h"
#import "HYBCommonAlertView.h"
#import "HYBAppCommonInfoTool.h"

@implementation HYBPhoneCallHelper

// 调用默认客服电话
+ (void)call {
  [self callWithPhone:[HYBAppCommonInfoTool servicePhone]];
}

+ (void)callWithPhone:(NSString *)phone {
  NSString *teleString = [NSString stringWithFormat:@"tel://%@", phone];
  NSURL *teleUrl = [NSURL URLWithString:teleString];
  if ([[UIApplication sharedApplication] canOpenURL:teleUrl]) {
    [[UIApplication sharedApplication] openURL:teleUrl];
  }
}

+ (void)callInController:(UIViewController *)controller {
  [self callInController:controller WithPhone:[HYBAppCommonInfoTool servicePhone]];
}

+ (void)callInController:(UIViewController *)controller WithPhone:(NSString *)phone {
  HYBCommonAlertView *alert = [[HYBCommonAlertView alloc] initWithFrame:CGRectMake(0, kScreenHeight, kScreenWidth, 140) title:@"咨询投诉、应聘美容师可拨打客服电话。" leftBlock:^{
    [self call];
  } rightBlock:^{
    DDLogVerbose(@"cancel to make a phone call");
  }];
  [alert showInController:controller];
}


2016-05-10 14:12:39 PianZhideNanRen 阅读数 379

打电话的方法有三种,网上说的人很多我这里只写一种大家推荐使用的

UIWebView *webView = [[UIWebView alloc]init];
    [webView setBackgroundColor:ClearColor];
    [self addSubview:webView];
    
    NSURL *url = [NSURL URLWithString:@"tel://10086"];
    [webView loadRequest:[NSURLRequest requestWithURL:url]];


这个web必须要要有父view,否则会不启动打电话功能
2015-12-25 11:05:20 sevenquan 阅读数 586

//一、打电话

    //1、用UIWebView加载电话,这种是合法的,可以上App Store

   UIWebView*callWebview =[[UIWebViewalloc] init];

   NSURL *telURL =[NSURLURLWithString:@"tel:10010"];

    [callWebviewloadRequest:[NSURLRequestrequestWithURL:telURL]];

    //记得添加到view

    [self.viewaddSubview:callWebview];

    

    

    //2、私有方法,貌似不能上App Store

    [[UIApplicationsharedApplication] openURL:[NSURLURLWithString:@"telprompt://10010"]];

    //[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://10010"]];


参考:

// 第一种方式打电话

[html] view plain copy
  1. - (void)makeACall{  
  2.      NSString *number = @"";// 此处读入电话号码  
  3.      NSString *num = [[NSString alloc] initWithFormat:@"tel://%@",number]; //number为号码字符串 如果使用这个方法 结束电话之后会进入联系人列表  
  4. }  

// 第二种方式打电话

[html] view plain copy
  1. - (void)makeACall{  
  2.     NSString *num = [[NSString alloc] initWithFormat:@"telprompt://%@",number]; //而这个方法则打电话前先弹框  是否打电话 然后打完电话之后回到程序中 网上说这个方法可能不合法 无法通过审核  
  3.     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:num]]; //拨号  
  4. }  

//  第三种方式打电话

// 下面的代码能在应用中添加一个电话按钮,UIWebView加载电话,这种是合法的,可以上App Store的。

[html] view plain copy
  1. -(void)makeACall{  
  2.     NSString *phoneNum = @"";// 电话号码  
  3.     NSURL *phoneURL = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",phoneNum]];  
  4.     if ( !phoneCallWebView ) {  
  5.         phoneCallWebView = [[UIWebView alloc] initWithFrame:CGRectZero];// 这个webView只是一个后台的View 不需要add到页面上来  效果跟方法二一样 但是这个方法是合法的  
  6.     }   
  7.     [phoneCallWebView loadRequest:[NSURLRequest requestWithURL:phoneURL]];  
  8. }  




//二、发短信

- (void)viewDidLoad {

    [superviewDidLoad];

   

    //iOS中可以使用两种方式发送短信,

    //1、使用openURL(但无法指定短信内容)

    [[UIApplicationsharedApplication]openURL:[NSURLURLWithString:@"sms://10010"]];//发短信

    

    //2、加入MessageUI.framework

    //#import <MessageUI/MessageUI.h>

    //添加协议:<MFMessageComposeViewControllerDelegate>

    [selfshowMessage];

}


- (void)showMessage

{

    

    if( [MFMessageComposeViewControllercanSendText] ){

        

        MFMessageComposeViewController * controller = [[MFMessageComposeViewControlleralloc]init];//autorelease];

        

        controller.recipients = [NSArrayarrayWithObject:@"10010"];

        controller.body =@"测试发短信";

        controller.messageComposeDelegate =self;

        

        [selfpresentViewController:controller animated:YEScompletion:nil];

        

        [[[[controller viewControllers]lastObject] navigationItem]setTitle:@"测试短信"];//修改短信界面标题

    }else{

        

        [selfalertWithTitle:@"提示信息"msg:@"设备没有短信功能"];

    }

}


//MFMessageComposeViewControllerDelegate

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{

    

    [controller dismissViewControllerAnimated:YEScompletion:nil];//关键的一句   不能为YES

    

   switch ( result ) {

            

        caseMessageComposeResultCancelled:

            

            [selfalertWithTitle:@"提示信息"msg:@"发送取消"];

           break;

        caseMessageComposeResultFailed:// send failed

            [selfalertWithTitle:@"提示信息"msg:@"发送成功"];

           break;

        caseMessageComposeResultSent:

            [selfalertWithTitle:@"提示信息"msg:@"发送失败"];

           break;

       default:

           break;

    }

}


- (void) alertWithTitle:(NSString *)title msg:(NSString *)msg {

    

    

   UIAlertView *alert = [[UIAlertViewalloc] initWithTitle:title

                                                   message:msg

                                                  delegate:self

                                         cancelButtonTitle:nil

                                         otherButtonTitles:@"确定",nil];

    

    [alertshow];

    

}



2015-11-24 19:03:46 CloverZhu 阅读数 782

赶着下班就不多说了, 初始化 UIWebView 名为 _phoneCallWebView,调用如下方法,注意下方 红色区域



#pragma mark -----打电话-------------

- (void)openPhoneCallViewWithphoneNumber:(NSString *)phoneNum

{

    if (_phoneCallWebView == nil) {

        _phoneCallWebView = [[UIWebView alloc] initWithFrame:CGRectZero];

    }

    NSString *newPhoneString = [要调用打电话功能的ViewController dealWithPhoneNumber:phoneNum];

    if ([要调用打电话功能的ViewController isMobileNumber:newPhoneString]) {

        

        NSURL* dialUrl = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@", newPhoneString]];

        if ([[UIApplication sharedApplication] canOpenURL:dialUrl])

        {

            if (_phoneCallWebView) {

                [_phoneCallWebView loadRequest:[NSURLRequest requestWithURL:dialUrl]];

            }

            else{

                [[UIApplication sharedApplication] openURL:dialUrl];

            }

        }

        else

        {

            

            UIAlertController  *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"设备不支持" preferredStyle:UIAlertControllerStyleAlert];

            

            UIAlertAction *cacelAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil];

            [alert addAction:cacelAction];

            [self presentViewController:alert animated:YES completion:nil];

            

            

            alert = nil;

        }

    } else {

        

        UIAlertController  *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"您选择的号码不合法" preferredStyle:UIAlertControllerStyleAlert];

        

        UIAlertAction *cacelAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil];

        [alert addAction:cacelAction];

        [self presentViewController:alert animated:YES completion:nil];

        

        alert = nil;

    }

}



#pragma mark ------处理电话号码


+ (NSString *)dealWithPhoneNumber:(NSString *)phone

{

    NSString *newPhone = [phone stringByReplacingOccurrencesOfString:@"-" withString:@""];

    return newPhone;

}



#pragma mark------判断是否是电话号码

+ (BOOL)isMobileNumber:(NSString *)mobileNum

{

    /**

     * 手机号码

     * 移动:134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188

     * 联通:130,131,132,152,155,156,185,186

     * 电信:133,1349,153,180,189

     */

    NSString * MOBILE = @"^1(3[0-9]|5[0-35-9]|8[025-9])\\d{8}$";

    /**

     * 中国移动:China Mobile

     * 134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188

     */

    NSString * CM = @"^1(34[0-8]|(3[5-9]|5[017-9]|8[278])\\d)\\d{7}$";

    /**

     * 中国联通:China Unicom

     * 130,131,132,152,155,156,185,186

     */

    NSString * CU = @"^1(3[0-2]|5[256]|8[56])\\d{8}$";

    /**

     * 中国电信:China Telecom

     * 133,1349,153,180,189

     */

    NSString * CT = @"^1((33|53|8[09])[0-9]|349)\\d{7}$";

    /**

     * 大陆地区固话及小灵通

     * 区号:010,020,021,022,023,024,025,027,028,029

     * 号码:七位或八位

     */

    

    NSString * PHS = @"^0(10|2[0-5789]|\\d{3})\\d{7,8}$";

    

    NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];

    NSPredicate *regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM];

    NSPredicate *regextestcu = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CU];

    NSPredicate *regextestct = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CT];

    NSPredicate *regextestphs = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", PHS];

    

    if (([regextestmobile evaluateWithObject:mobileNum] == YES)

        || ([regextestcm evaluateWithObject:mobileNum] == YES)

        || ([regextestct evaluateWithObject:mobileNum] == YES)

        || ([regextestcu evaluateWithObject:mobileNum] == YES)

        || ([regextestphs evaluateWithObject:mobileNum] == YES))

    {

        return YES;

    }

    else

    {

        return YES; //暂时不做检查

    }

}

ios调打电话代码

阅读数 505

ios-打电话

阅读数 320

iOS 唤起拨打电话打电话功能

博文 来自: DDCXYZL
没有更多推荐了,返回首页