Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/extensions/Variables/includes/ExtVariables.php on line 198
CTIndicators - iPhone Development Wiki

CTIndicators

From iPhone Development Wiki
Revision as of 22:34, 23 June 2013 by Cykey (talk | contribs) (Created page with "'''CTIndicators''' is an API in CoreTelephony.framework that can be used to get the signal strength, voicemail status, etc. == Getting the cellular signal strength == The...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

CTIndicators is an API in CoreTelephony.framework that can be used to get the signal strength, voicemail status, etc.

Getting the cellular signal strength

The code below can be used to get the raw strength, graded strength as well as the number of bars (as seen in the status bar).

#include <CoreFoundation/CoreFoundation.h>
#include <CoreTelephony/CoreTelephony.h>

static void SignalStrengthDidChange()
{
    long int raw = 0;
    long int graded = 0;
    long int bars = 0;

    CTIndicatorsGetSignalStrength(&raw, &graded, &bars);

    printf("Signal strength changed! Raw: %li, graded: %li bars: %li\n", raw, graded, bars);
    // Prints something like:
    // Signal strength changed! Raw: -96, graded: 27 bars: 3
}

int main(int argc, char *argv[])
{
    // Register as a listener to the kCTIndicatorsSignalStrengthNotification notification to be notified when the signal strength changed.
    CTTelephonyCenterAddObserver(CTTelephonyCenterGetDefault(), NULL, (CFNotificationCallback)SignalStrengthDidChange, kCTIndicatorsSignalStrengthNotification, NULL, CFNotificationSuspensionBehaviorCoalesce);

    // Get the initial strength.
    SignalStrengthDidChange();

    CFRunLoopRun();

    return 0;
}

References