Use coretelephony to get the SIM card network operator name

Source: Internet
Author: User

Time:

Conversion from below

Http://zonble.net/archives/2010_06/1330.php.

/System/library/frameworks/coretelephony. Framework/headers to build settings
Header search paths, and add header files in these classes, such as 1. # im

Conversion from http://zonble.net/archives/2010_06/1330.php below
Add the header file directory/system/library/frameworks/coretelephony. Framework/headers to build to set the header search paths and add the header file in these classes. For example
1. # import "ctcarrier. H"
2. # import "cttelephonynetworkinfo. H"

In the official API of IOS 4.0, a framework called core telephony is added.
Telephony is a private API. It is open now, but from the perspective of files, there are few lines in it, neither telling you how to use them nor examples.
The four class headers in the framework cannot clearly figure out the purpose of using this item.

At present, I only know that I can do two things: 1. I know which carrier service your iPhone is currently using, and 2. I know if the iPhone is making a phone call.

※Carrier Information

Use the cttelephonynetworkinfo and ctcarrier classes to obtain carrier information, for example:

Cttelephonynetworkinfo * info = [[cttelephonynetworkinfo alloc] init];
Ctcarrier * carrier = info. subscribercellularprovider;
Nslog (@ "carrier: % @", [carrier description]);

The result is as follows:

Ctcarrier (0x140dc0 ){
Carrier name: [China Telecom]
Mobile Country Code
: [466]
Mobile network code: [92]
ISO country code: [TW]
Allows VoIP? [Yes]
}

Then, if you feed a block to cttelephonynetworkinfo, for example:

Info. subscribercellularproviderdidupdatenotifier = ^ (ctcarrier * carrier) {nslog (@ "carrier: % @", [carrier description]);};

As a result, when your iPhone is roaming to another network
Block, but the only thing you can do is to know which carrier's network the mobile phone is roaming in. Some services are closely related to telecom carriers. You may decide what functions are available in the software.
It is necessary for a carrier to use the network; when the carrier is doing the iPhone software, it will probably want to do this.
※Call Materials

Using the ctcallcenter and ctcall classes, you can know whether the iPhone is currently on call. The ctcallcenter is used to monitor whether a call is received, received, or hung up, while the ctcall is
Package into an object. Let's write a short program-

Ctcallcenter * center = [[ctcallcenter alloc] init];
Center. calleventhandler = ^ (ctcall * Call ){
Nslog (@ "Call: % @", [Call description]);
};

Then, execute the command on the real machine, connect the phone to the iPhone, connect the phone to the iPhone, and then immediately end up, why can't I pass my phone bill to test the program ?) We can see that the iPhone has executed our block and dumped the ctcall object:

Ctcall (0x143400 ){
Callstate: [ctcallstateincoming]
Call ID: [CE5F9337-1990-4254-8797-1CCEA85B061B]
}
Ctcall (0x10bac0 ){
Callstate: [ctcallstatedisconnected]
Call ID: [CE5F9337-1990-4254-8797-1CCEA85B061B]
}

The ctcall object has only two attributes. One is the call status (incoming call, in call ...), The second is the unique ID of the call. There is no other information. You cannot know where the call is from. You can only know that the call is in, and you cannot call the call through this API.

The purpose that can be imagined in a big sense is that when your program runs halfway, the program process is interrupted by phone, and at this time it may interrupt what was originally being done, resume after the call ends.

Finally, ctcallcenter and cttelephonynetworkinfo cannot be used in the simulator. After calling alloc and init, the returned results will only be nil.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.