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: Difference between revisions - iPhone Development Wiki

CTIndicators: Difference between revisions

From iPhone Development Wiki
(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...")
(No difference)

Revision as of 22:34, 23 June 2013

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