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...")
 
m (Polish)
 
Line 7: Line 7:
#include <CoreTelephony/CoreTelephony.h>
#include <CoreTelephony/CoreTelephony.h>


static void SignalStrengthDidChange()
static void SignalStrengthDidChange(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo)
{
{
    long int raw = 0;
long int raw = 0;
    long int graded = 0;
long int graded = 0;
    long int bars = 0;
long int bars = 0;


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


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


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


    // Get the initial strength.
// Get the initial strength.
    SignalStrengthDidChange();
SignalStrengthDidChange();


    CFRunLoopRun();
CFRunLoopRun();


    return 0;
return 0;
}
}


</source>
</source>


== References ==  
== External links ==
* '''Header''': https://github.com/Cykey/ios-reversed-headers/blob/master/CoreTelephony/CTIndicators.h
 
* Header: https://github.com/Cykey/ios-reversed-headers/blob/master/CoreTelephony/CTIndicators.h


{{occlass|library=CoreTelephony.framework|navbox=1}}
{{occlass|library=CoreTelephony.framework|navbox=1}}

Latest revision as of 13:34, 28 October 2014

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(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo)
{
	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, SignalStrengthDidChange, kCTIndicatorsSignalStrengthNotification, NULL, CFNotificationSuspensionBehaviorCoalesce);

	// Get the initial strength.
	SignalStrengthDidChange();

	CFRunLoopRun();

	return 0;
}

External links