BluetoothManager Framework Notifications List - iphone

I want to get all the notifications of the BluetoothManager private framework. I've been searching but i only have found two (BluetoothAvailabilityChangedNotification and BluetoothDeviceDiscoveredNotification).
I'm interesting in a notification that reports if iphone connected/disconnected to a device. If anyone could get me a list of all notifications i will be appreciated.

I don't have a full list, but these are the ones you were interested in:
BluetoothDeviceConnectFailedNotification
BluetoothDeviceConnectSuccessNotification
BluetoothDeviceDisconnectFailedNotification // haven't confirmed this one
BluetoothDeviceDisconnectSuccessNotification
Here are some others:
BluetoothConnectabilityChangedNotification // fires when bluetooth is turned on/off
BluetoothAvailabilityChangedNotification // seems to fire once at app start)
BluetoothPowerChangedNotification
BluetoothDeviceDiscoveredNotification
BluetoothDeviceRemovedNotification
BluetoothPairingUserNumericComparisionNotification
BluetoothPairingPINResultSuccessNotification

Add before you call [BluetoothManager sharedInstance]:
CFNotificationCenterAddObserver(CFNotificationCenterGetLocalCenter(),
NULL,
bluetoothCallback,
NULL,
NULL,
CFNotificationSuspensionBehaviorDeliverImmediately);
and somewhere in this implementation the method void bluetoothCallback:
void bluetoothCallback (CFNotificationCenterRef center,
void *observer,
CFStringRef name,
const void *object,
CFDictionaryRef userInfo)
{
if (CFStringGetCharacterAtIndex(name, 0) == 'B') { // stupid way to filter for only 'B'luetooth notifications
NSLog(#"%#", name);
}
}
Your console log shows you all bluetooth notifications now.

Related

Does Apple allow to monitor springboard events?

I am trying to detect when a user locks the device (vs. pressing home button for instance).
Found this:
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), //center
NULL, // observer
lockStateChanged, // callback
CFSTR("com.apple.springboard.lockstate"), // event name
NULL, // object
CFNotificationSuspensionBehaviorDeliverImmediately);
static void lockStateChanged(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
NSLog(#"event received!");
// you might try inspecting the `userInfo` dictionary, to see
// if it contains any useful info
if (userInfo != nil) {
CFShow(userInfo);
}
}
I can imagine that com.apple.springboard.lockstate is like calling private API? Or is this fine?
Assuming all the CF... functions are public you are probably OK, but in a murky area for sure. Next release of iOS could break your code if Apple changes that string.
What I did in a similar situation for an approved shipping app was to avoid using the string directly. Create an array of the strings, then use the NSString method to combine them with a period separator instead of using com.apple.springboard.lockstate directly.
YMMV

Detect Headphones Unplugged - Monotouch

Is there a way to detect if headphones are unplugged in Monotouch? I am trying to look for the AudioSessionAddPropertyListener method but don't see it. What this method ported over?
Here is Apple's docs: http://developer.apple.com/library/ios/#documentation/AudioToolbox/Reference/AudioSessionServicesReference/Reference/reference.html#//apple_ref/doc/constant_group/Audio_Session_Interruption_States
If anyone wants to see the code for how to do this, you can do the following:
AudioSession.PropertyListener p = delegate(AudioSessionProperty prop, int size, IntPtr data) {
NSDictionary propertyDictionary = new NSDictionary(data);
if (propertyDictionary.ContainsKey(NSObject.FromObject("OutputDeviceDidChange_OldRoute")))
{
string oldRoute = propertyDictionary.ValueForKey(new NSString("OutputDeviceDidChange_OldRoute")).ToString();
if (oldRoute == "Headphone")
{
if (audioPlayer != null)
{
audioPlayer.Pause();
}
}
}
};
AudioSession.AddListener(AudioSessionProperty.AudioRouteChange, p);
Is there a way to detect if headphones are unplugged in Monotouch?
I'm not sure but...
I am trying to look for the AudioSessionAddPropertyListener method but don't see it. What this method ported over?
The native call to AudioSessionAddPropertyListener maps to MonoTouch's AudioSession.AddListener static method.

How to find out if the iPhone is on silent mode?

I have a mailing application. If the user sends a mail successfully, then I need to notify that the mail was sent successfully. For that, I need to know if his phone is on silent mode
(in which case there will be a 'vibrate') or regular mode (in which case there will be a 'beep'). Can anyone help me with it?
Thanks in advance
If you use the correct audio session type, iOS will handle this for you:
http://developer.apple.com/library/ios/#documentation/Audio/Conceptual/AudioSessionProgrammingGuide/Introduction/Introduction.html
CFStringRef state;
UInt32 propertySize = sizeof(CFStringRef);
AudioSessionInitialize(NULL, NULL, NULL, NULL);
AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &propertySize, &state);
if(CFStringGetLength(state) == 0)
{
//SILENT
}
else
{
//NOT SILENT
}
If the state string is empty then the phone is on silent - otherwise the phone has an audio output
EDIT:
remember to add the AudioToolbox framework and import. – Thomas Clayson
answer taken from (http://iphone-dev-tips.alterplay.com/2009/12/iphone-silent-mode-detection.html)

how to run vibrate continuously in iphone?

In my application I'm using following coding pattern to vibrate my iPhone device
Include: AudioToolbox framework
Header File:
#import "AudioToolbox/AudioServices.h"
Code:
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
My problem is that when I run my application it gets vibrate but only for second but I want that it will vibrate continuously until I will stop it.
How could it be possible?
Thankfully, it's not possible to change the duration of the vibration. The only way to trigger the vibration is to play the kSystemSoundID_Vibrate as you have. If you really want to though, what you can do is to repeat the vibration indefinitely, resulting in a pulsing vibration effect instead of a long continuous one. To do this, you need to register a callback function that will get called when the vibration sound that you play is complete:
AudioServicesAddSystemSoundCompletion (
kSystemSoundID_Vibrate,
NULL,
NULL,
MyAudioServicesSystemSoundCompletionProc,
NULL
);
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
Then you define your callback function to replay the vibrate sound again:
#pragma mark AudioService callback function prototypes
void MyAudioServicesSystemSoundCompletionProc (
SystemSoundID ssID,
void *clientData
);
#pragma mark AudioService callback function implementation
// Callback that gets called after we finish buzzing, so we
// can buzz a second time.
void MyAudioServicesSystemSoundCompletionProc (
SystemSoundID ssID,
void *clientData
) {
if (iShouldKeepBuzzing) { // Your logic here...
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
} else {
//Unregister, so we don't get called again...
AudioServicesRemoveSystemSoundCompletion(kSystemSoundID_Vibrate);
}
}
There are numerous examples that show how to do this with a private CoreTelephony call: _CTServerConnectionSetVibratorState, but it's really not a sensible course of action since your app will get rejected for abusing the vibrate feature like that. Just don't do it.
Read the Apple Human Interaction Guidelines for iPhone. I believe this is not approved behavior in an app.
iOS 5 has implemented Custom Vibrations mode. So in some cases variable vibration is acceptable. The only thing is unknown what library deals with that (pretty sure not CoreTelephony) and if it is open for developers. So keep on searching.
The above answers are good and you can do it in a simple way also.
You can use the recursive method calls.
func vibrateTheDeviceContinuously() throws {
// Added concurrent queue for next & Vibrate device
DispatchQueue.global(qos: .utility).async {
//Vibrate the device
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
self.incrementalCount += 1
usleep(800000) // if you don't want pause in between, remove this line.
do {
if let isKeepBuzzing = self.iShouldKeepBuzzing , isKeepBuzzing == true {
try self.vibrateTheDeviceContinuously()
}
else {
return
}
} catch {
//Exception handle
print("exception")
}
}
}
To stop the device vibration use the following line.
self.iShouldKeepBuzzing = false
ios swift

Programmatically getting the iPhone's carrier signal strength

Is there a way to get the iPhone's carrier, and/or the current signal strength, using Objective-C? I know how to determine if a data connection is present, and whether or not that connection is wi-fi vs. cellular. I also know that you can manually place the iPhone into "field test" mode by going to the phone app, and dialing #3001*12345*# and hitting Send.
You made me curious and I found out that it's actually *3001#12345#* (hashes and stars exchanged).
This probably won't pass Apple's review, but you can use CTTelephony notifications.
First, link against CTTelephony.
Now just use this:
static void callback(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
CFShow(name)
NSString *sName = name;
if ([sName isEqualToString:#"kCTIndicatorsSignalStrengthNotification"]) {
if (userInfo) CFShow(userInfo);
}
}
And this to subscribe:
id ct = CTTelephonyCenterGetDefault();
CTTelephonyCenterAddObserver(
ct,
NULL,
callback,
NULL,
NULL,
NULL);