//
// CCPhone.h
// CCFC
//
// Created by xichen on 11-12-16.
// Copyright 2011年 ccteam. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "CCConfig.h"
#import "CCDepend.h"
#import <CoreTelephony/CTCall.h>
#import "CCCommon.h"
#if CC_ENABLE_PRIVATE_API
CC_EXTERN NSDictionary *CTSettingCopyMyPhoneNumberExtended() _Depended_On_CoreTelephony_;
CC_EXTERN CFNotificationCenterRef CTTelephonyCenterGetDefault() _Depended_On_CoreTelephony_;
CC_EXTERN void CTTelephonyCenterAddObserver(
CFNotificationCenterRef center,
const void *observer,
CFNotificationCallback callBack,
CFStringRef name,
const void *object,
CFNotificationSuspensionBehavior suspensionBehavior) _Depended_On_CoreTelephony_;
CC_EXTERN void CTTelephonyCenterRemoveObserver(CFNotificationCenterRef center,
const void *observer,
CFStringRef name,
const void *object) _Depended_On_CoreTelephony_;
CC_EXTERN NSString *CTCallCopyAddress(void *, CTCall *call) _Depended_On_CoreTelephony_; //获得来电号码
CC_EXTERN void CTCallDisconnect(CTCall *call) _Depended_On_CoreTelephony_; // 挂断电话
CC_EXTERN void CTCallAnswer(CTCall *call) _Depended_On_CoreTelephony_; // 接电话
CC_EXTERN int CTCallGetStatus(CTCall *call) _Depended_On_CoreTelephony_; // get the status of the call
#endif
@interface CCPhone : NSObject
{
}
// 拨打号码
+ (BOOL)call:(NSString *)phoneNo;
// get the carrier code
+ (NSString *)getCarrierCode __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_0);
// get the SIM type info, eg, China Mobile, China Telecom, and so on
+ (NSString *)getSIMCarrierName:(NSString *)carrierCode __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_0);
#if CC_ENABLE_PRIVATE_API
+ (NSDictionary *)getPhoneNumberDict;
+ (NSString *)getPhoneNumber; // maybe returs nil
+ (NSString *)getPhoneNumberByUserDefaults; // maybe returs nil
#endif
@end
//
// CCPhone.m
// CCFC
//
// Created by xichen on 11-12-16.
// Copyright 2011年 ccteam. All rights reserved.
//
#import "CCPhone.h"
#import "CCNSString.h"
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
#import <CoreTelephony/CTCarrier.h>
@implementation CCPhone
// 拨打号码
+ (BOOL)call:(NSString *)phoneNo
{
NSString *str = [NSString stringWithFormat:@"tel://%@", phoneNo];
return [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
}
// get the carrier code
+ (NSString *)getCarrierCode __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_0)
{
CTTelephonyNetworkInfo *info = [[[CTTelephonyNetworkInfo alloc] init] autorelease];
CTCarrier *carrier = info.subscriberCellularProvider;
return carrier.mobileNetworkCode;
}
// get the SIM type info, eg, ChinaMobile, ChinaTelecom, and so on
+ (NSString *)getSIMCarrierName:(NSString *)carrierCode __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_0)
{
if([carrierCode stringInArr:[NSArray arrayWithObjects:@"00", @"02", @"07", nil]])
return @"China Mobile";
if([carrierCode stringInArr:[NSArray arrayWithObjects:@"01", @"06", nil]])
return @"China Unicom";
if([carrierCode stringInArr:[NSArray arrayWithObjects:@"03", @"05", nil]])
return @"China Telecom";
if([carrierCode stringInArr:[NSArray arrayWithObjects:@"20", nil]])
return @"China Tietong";
return nil;
}
#if CC_ENABLE_PRIVATE_API
+ (NSDictionary *)getPhoneNumberDict
{
return CTSettingCopyMyPhoneNumberExtended();
}
+ (NSString *)getPhoneNumber // maybe returs nil
{
NSDictionary *dict = CTSettingCopyMyPhoneNumberExtended();
return [[[dict objectForKey:@"kCTSettingMyPhoneNumber"] retain] autorelease];
}
+ (NSString *)getPhoneNumberByUserDefaults // maybe returs nil
{
return [[[[NSUserDefaults standardUserDefaults] valueForKey:@"SBFormattedPhoneNumber"] retain] autorelease];
}
#endif
@end
微风不燥,阳光正好,你就像风一样经过这里,愿你停留的片刻温暖舒心。
我是程序员小迷(致力于C、C++、Java、Kotlin、Android、Shell、JavaScript、TypeScript、Python等编程技术的技巧经验分享),若作品对您有帮助,请关注、分享、点赞、收藏、在看、喜欢,您的支持是我们为您提供帮助的最大动力。
欢迎关注。助您在编程路上越走越好!
标签:__,return,CC,void,ios,NSString,import,CCPhone From: https://blog.csdn.net/cxsjabcabc/article/details/7173961