IOS 完成来电归属地
首先是一个库:(有时间在上传)
然后设置一个工具类
.h
@interface HMFoundLocation : NSObject AS_SINGLETON(HMFoundLocation) @property(nonatomic,strong)NSString *address; @property(nonatomic,strong)NSString *operater; // 设置归属地 和 运营商两个属性
- (void)setAddressAndOperater:(NSString *)telephoneNumber; @end
.m
//
// HMFoundLocation.m
// contactModel
//
// Created by mac_mini on 14-10-24.
// Copyright (c) 2014年 mac_mini. All rights reserved.
// #import "HMFoundLocation.h"
#import <sqlite3.h> @implementation HMFoundLocation DEF_SINGLETON(HMFoundLocation) - (void)setAddressAndOperater:(NSString *)telephoneNumber{
NSInteger lengthOftel = [telephoneNumber length];
if (lengthOftel == ) {
[self _doAsServiceNumber:telephoneNumber];
} else if ((lengthOftel == ) && ([telephoneNumber characterAtIndex:] == '')) {
// 11位手机号 不含+86
NSString *findNumber = [telephoneNumber stringByPaddingToLength: withString:nil startingAtIndex:];
NSString *findNumberMobile = [telephoneNumber stringByPaddingToLength: withString:nil startingAtIndex:];
[self _selectInfoByPhone:findNumber WithMobile:findNumberMobile];
} else if ((lengthOftel == ) && ([telephoneNumber characterAtIndex:] == '')) {
// 固话以零开头 区号为3位
NSString *zoneNumber = [telephoneNumber stringByPaddingToLength: withString:nil startingAtIndex:];
NSRange range;
range.location = ;
range.length = ;
[self _doAsLinePhone:zoneNumber];
self.operater = @"固话";
} else if (((lengthOftel == ) && ([telephoneNumber characterAtIndex:] == '')) || ((lengthOftel == ) && ([telephoneNumber characterAtIndex:] == ''))) {
// 固话以零开头 区号为4位
NSString *zoneNumber = [telephoneNumber stringByPaddingToLength: withString:nil startingAtIndex:];
NSRange range;
range.location = ;
range.length = ;
[self _doAsLinePhone:zoneNumber];
self.operater = @"固话";
}
else{
[self _numberUnknown];
}
} - (void)_selectInfoByPhone:(NSString *)findNumber WithMobile:(NSString *)findNumberMobile{
NSString *SelectWhatMobile = @"SELECT mobile FROM numbermobile where uid=";
NSString *SelectWhatMobileFull = [SelectWhatMobile stringByAppendingFormat:@"%@",findNumberMobile];
sqlite3 *database;
if (sqlite3_open([[self _findDatabase] UTF8String], &database)
!= SQLITE_OK) {
sqlite3_close(database);
NSAssert(, @"Failed to open database");
}
// 获取运营商名称
sqlite3_stmt *stmt;
if (sqlite3_prepare_v2(database, [SelectWhatMobileFull UTF8String], -, &stmt, nil) == SQLITE_OK) {
while (sqlite3_step(stmt) == SQLITE_ROW) {
int mobilenumber = sqlite3_column_int(stmt, );
if (mobilenumber) {
NSString *mobileNumberString = [NSString stringWithFormat:@"%d",mobilenumber];
NSString *SelectWhatMobileName = @"SELECT mobile FROM mobilenumber WHERE uid=";
NSString *SelectWhatMobileNameFull = [SelectWhatMobileName stringByAppendingFormat:@"%@",mobileNumberString];
sqlite3_stmt *stmt2;
if (sqlite3_prepare_v2(database, [SelectWhatMobileNameFull UTF8String], -, &stmt2, nil) == SQLITE_OK) {
while (sqlite3_step(stmt2) == SQLITE_ROW) {
char *mobilename = (char *)sqlite3_column_text(stmt2, );
NSString *mobilenamestring = [[NSString alloc] initWithUTF8String:mobilename];
if (mobilenamestring!= NULL) {
self.operater = mobilenamestring;
}
}
}sqlite3_finalize(stmt2);
}
}
sqlite3_finalize(stmt);
}
// 获取手机号码归属地
sqlite3_stmt *stmt3;
NSString *SelectCityNumberByPhoneNumber = @"SELECT city FROM phonenumberwithcity WHERE uid=";
NSString *SelectCityNumberByPhoneNumberFull = [SelectCityNumberByPhoneNumber stringByAppendingFormat:@"%@",findNumber];
if (sqlite3_prepare_v2(database, [SelectCityNumberByPhoneNumberFull UTF8String], -, &stmt3, nil) == SQLITE_OK) {
if (sqlite3_step(stmt3) == SQLITE_ROW) {
int citynumber = sqlite3_column_int(stmt3, );
NSString *citynumberNSString = [NSString stringWithFormat:@"%d",citynumber];
if (citynumberNSString != nil) {
NSString *SelectCityNameAndCtiyZoneByCityBumber = @"SELECT city,zone FROM citywithnumber WHERE uid=";
NSString *SelectCityNameAndCtiyZoneByCityBumberFull = [SelectCityNameAndCtiyZoneByCityBumber stringByAppendingFormat:@"%@",citynumberNSString];
sqlite3_stmt *stmt4;
if (sqlite3_prepare_v2(database, [SelectCityNameAndCtiyZoneByCityBumberFull UTF8String], -, &stmt4, nil) == SQLITE_OK) {
if (sqlite3_step(stmt4) == SQLITE_ROW) {
char *cityname = (char *)sqlite3_column_text(stmt4, );
int cityzonecode = sqlite3_column_int(stmt4, );
NSString *cityNameNSString = [[NSString alloc] initWithUTF8String:cityname];
NSString *cityzonecodeNnumber = [@"" stringByAppendingFormat:@"%d",cityzonecode];
if (cityNameNSString != nil && cityzonecodeNnumber != nil) {
self.address = cityNameNSString;
}
}else {
[self _numberUnknown];
}
sqlite3_finalize(stmt4);
}
}
}else {
[self _numberUnknown];
}
sqlite3_finalize(stmt3);
}
sqlite3_close(database);
} // 私有方法
-(NSString *)_findDatabase{
NSString *path = [[NSBundle mainBundle] pathForResource:@"location_Numbercity_citynumber" ofType:@"db"];
return path;
} - (void)_doAsServiceNumber:(NSString *)telephoneNumber{
if([telephoneNumber isEqualToString:@""]){
self.address = @"中国电信客服";
self.operater = @"中国电信";
}else if([telephoneNumber isEqualToString:@""]){
self.address = @"中国电信自助服务热线";
self.operater = @"中国电信";
}else if([telephoneNumber isEqualToString:@""]){
self.address = @"中国联通客服";
self.operater = @"中国联通";
}else if([telephoneNumber isEqualToString:@""]){
self.address = @"中国联通充值";
self.operater = @"中国联通";
}else if([telephoneNumber isEqualToString:@""]){
self.address = @"中国移动客服";
self.operater = @"中国移动";
}else{
[self _numberUnknown];
}
} - (void)_doAsLinePhone:(NSString*)telephoneNumber{
NSString *SelectCityNameByCityZoneCode = @"SELECT city FROM citywithnumber WHERE zone=";
NSString *SelectCityNameByCityZoneCodeFull = [SelectCityNameByCityZoneCode stringByAppendingString:telephoneNumber ];
sqlite3 *database;
if (sqlite3_open([[self _findDatabase] UTF8String], &database)
!= SQLITE_OK) {
sqlite3_close(database);
NSAssert(, @"Failed to open database");
}
sqlite3_stmt *stmt;
if (sqlite3_prepare_v2(database, [SelectCityNameByCityZoneCodeFull UTF8String], -, &stmt, nil) == SQLITE_OK) {
if (sqlite3_step(stmt) == SQLITE_ROW) {
char *cityname = (char *)sqlite3_column_text(stmt, );
NSString *cityNameNSString = [[NSString alloc] initWithUTF8String:cityname];
if (cityname != nil) {
self.address = cityNameNSString;
}
}else {
[self _numberUnknown];
}
sqlite3_finalize(stmt);
}
sqlite3_close(database);
} - (void)_numberUnknown{
self.address = @"未知";
self.operater = @"未知";
} @end
这个实例,用到了数据库,首先要把数据库拖到工程中来,然后在Build Phases的Copy Bundle Resources中添加进来。
然后在用到数据库的地方,import sqlite3.h 这个文件夹,里面是系统提供的数据库管理类。具体用法可在网上寻找。
IOS 完成来电归属地的更多相关文章
- IOS获取来电去电来电归属系统通知达到效果(一)
这里的原理是获得到呼叫系统通知,然后根据本地呼叫电话号码,相应的电话联系. 一世. 来电显示是不是在地址簿中的联系人, 这是当第一个加入一个临时的联系人在您的电话簿(它是创建一个新的接触,并保存相 ...
- ios应用来电监听
先导入这两个头文件,库文件不用导可以 #import <CoreTelephony/CTCallCenter.h> #import <CoreTelephony/CTCall.h&g ...
- iOS 判断来电状态CTCallCenter代码块不执行问题的解决
项目中需要检测来电状态,使用了CTCallCenter,在AppDelegate中,代码如下: CTCallCenter *callCenter = [[CTCallCenter alloc] i ...
- C# 号码归属地查询算法(根据Android来电归属地二进制文件查询修改)
前言 近期有个项目需要用到号码归属查询,归属地数据库可能比不上ip138,淘宝上也有卖的-,-! 文本提供一个279188条记录并压缩成562KB的归属地数据.我在互联网上搜索了相关文章,要不是数据库 ...
- 关于iOS7越狱的整理
目前越狱非常的不稳定,已经白苹果第三次了.中途遇见了不少问题,去各大论坛找了下解决办法,算是搬运工. iOS7越狱过程中打开手机上的“evasi0n7”闪退,怎么办?1. 请先尝试卸载手机“evasi ...
- iphone5s越狱之后必装
一.iphone5s完美越狱之后必装插件一览表 由于iPhone5s配置了强大的64位的A7处理器,所以在iOS7完美越狱后,不少iPhone5s用户发现之前安装的大部分人们插件在越狱后难以兼容.但是 ...
- 2016WWDC详解
今年苹果WWDC 2016上把所有系统都更新了个遍,watchOS.tvOS.macOS 和 iOS 都或多或少带来了新功能. 本文的主角是更新最多的 iOS 10,第一时间在一部 iPhone 6s ...
- Android核心基础(手机卫士的一个知识点总结)
注意:有些功能是需要权限的,在这里并没有写出来,在程序运行中,根据程序报的错误,添加相应的权限即可,里面的具体里面可能有一些小细节,没有明确的写出来,具体的需要在程序中自己调试,解决. 这个总结涵盖了 ...
- C# 号码归属地查询算法
C# 号码归属地查询算法(根据Android来电归属地二进制文件查询修改) 前言 近期有个项目需要用到号码归属查询,归属地数据库可能比不上ip138,淘宝上也有卖的-,-! 文本提供一个279188条 ...
随机推荐
- codevs 1299 切水果 线段树
1299 切水果 时间限制: 1 s 空间限制: 128000 KB 题目描述 Description 简单的说,一共N个水果排成一排,切M次,每次切[L,R]区间的所有水果(可能有的水果 ...
- adobe flash player 下载地址
1. https://www.adobe.com/cn/products/flashplayer/distribution3.html
- 有關WCF一個自認爲比較經典的博客
无废话WCF入门教程四[WCF的配置文件] (http://www.cnblogs.com/iamlilinfeng/archive/2012/10/02/2710224.html) -------- ...
- JS中的forEach、$.each、map方法推荐
下面小编就为大家带来一篇JS中的forEach.$.each.map方法推荐.小编觉得挺不错的,现在分享给大家,也给大家做个参考.一起跟随小编过来看看吧 orEach是ECMA5中Array新方法中最 ...
- appium界面元素介绍
一.主窗口 主页面顶部从左到右依次是: AndroidSettings:android相关的设置 GeneralSettings:全局设置,设置appium相关的内容 DeveloperSetting ...
- Oracle学习笔记_04_多表查询
一.概念: 1.多表连接有以下几种分法: (1)内连接 vs 外连接 (左.右.满) (2)等值连接 vs 不等值连接 (3)非自连 ...
- PHP使用http_build_query()构造URL字符串的方法
http_build_query http_build_query -- 生成 url-encoded 之后的请求字符串描述string http_build_query ( array formda ...
- png8 png24 png32
解释 PNG8 : 8位的PNG最多支持256(2的8次方)种颜色,8位的PNG支持不透明.索引透明.alpha透明. PNG24 : 支持2的24次方种颜色,表现为不透明.PS导出PNG24是会根据 ...
- codeforces 622B B. The Time
B. The Time time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- urllib,urlib2与httplib,urllib3
urllib:编码参数离不开urllib,urllib.urlencode, urllib.urlopen(URL,[,data]) 支持POST,根据参数区分post或者get urllib2:发送 ...