自己写了个调起打电话的类,只需要修改一点点就可以直接使用:
// // 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];
}