Not getting EA notification with bluetooth - ios

I am able to get EA notification when connecting to an external device (MFi compliant) via USB but not via Bluetooth. Why is EA notification not being fired for Bluetooth connection, contrary to what the documentation suggests?

1) Did you set the Protocol String correctly in your InfoPlist?
2) Did you set the Protocol String correctly in your bluetooth device?
3) Did you register for incoming connection event? like this way:
-(void) <someMethod> {
[[EAAccessoryManager sharedAccessoryManager] registerForLocalNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(accessoryConnected:)
name:EAAccessoryDidConnectNotification
object:nil];
}
-(void)accessoryConnected: (NSNotification *)notification {
EAAccessory *accessory = [[notification userInfo] objectForKey:EAAccessoryKey];
NSLog(#"%# connected", accessory.name);
}

Related

Parse Live Query handling Error

I'm using parse live query for realtime communication and works for every types of events, but my problem is it happens that the server disconnect or internet connection is down so how can i handle error block ?
I try to make error block in subscription as an event
.handleError(<#T##handler: (PFQuery<Blocks>, Error) -> Void##(PFQuery<Blocks>, Error) -> Void#>)
but without success, I want to capture the error which is logged
2018-02-21 22:14:55.050543+0100 Youz[2095:1024917] TCP Conn 0x106d13f40
Failed : error 0:50 [50]
2018-02-21 22:14:55.051443+0100 Youz[2095:1024955] ParseLiveQuery:
WebSocket did disconnect with error: Optional(Error
Domain=NSPOSIXErrorDomain Code=50 "Network is down" UserInfo=
{_kCFStreamErrorCodeKey=50, _kCFStreamErrorDomainKey=1})
2018-02-21 22:14:55.057945+0100 Youz[2095:1024917] []
nw_connection_get_connected_socket 971 Connection has no connected
handler
You can capture Websocket Events with NSNotificationCenter.
just like this.
-(void) OnWebsocketConnected : (NSNotification *) noti {
DLogInfo(#"OnWebsocketConnected, noti= %#", noti);
}
-(void) OnWebsocketDisconnected : (NSNotification *) noti {
DLogInfo(#"OnWebsocketDisconnected, noti= %#", noti);
// can't recover lost data on Parse live query, we need to query manually.
}
-(void) OnWebsocketError : (NSNotification *) noti {
DLogInfo(#"OnWebsocketError, noti= %#", noti);
}
-(void) initializer {
......
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(OnWebsocketConnected:) name:#"WebsocketDidConnectNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(OnWebsocketDisconnected:) name:#"WebsocketDidDisconnectNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(OnWebsocketError:) name:#"WebsocketDisconnectionErrorKeyName" object:nil];
.......
}

Sending messages from the application to twitter in certain conditions

Can application send a message in twitter without user intervention under certain conditions? For example when charging the battery less 10%?
please, sorry for bad english!
You can monitor battery level like so:
UIDevice *device = [UIDevice currentDevice];
device.batteryMonitoringEnabled = YES;
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(batteryChanged:) name:#"UIDeviceBatteryLevelDidChangeNotification" object:device];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(batteryChanged:) name:#"UIDeviceBatteryStateDidChangeNotification" object:device];
// Your notification handler
- (void)batteryChanged:(NSNotification *)notification
{
UIDevice *device = [UIDevice currentDevice];
if(device.batteryLevel <= 10)
[self twittBatteryLevel: device.batteryLevel];
}
And then implement -(void)twittBatteryLevel:(float)batteryLevel as you would using twitter API

The difference between these two scheduled method calls - iOS

I have seen this around a few times but can't seem to find what is the difference between the two ...
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(loginViewFetchedUserInfo:)
name:FBSDKProfileDidChangeNotification
object:nil];
- (void)loginViewFetchedUserInfo:(NSNotification *)notification
and
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(loginViewFetchedUserInfo)
name:FBSDKProfileDidChangeNotification
object:nil];
- (void)loginViewFetchedUserInfo
I know that (void)methodname:(TYPE *)newName can pass in a value to the method but I don't know what the difference is in the two above and why you would do the first one (which is used in the Facebook SDK example) over the second one.
The first method passes the NSNotification object to the method. This way allows you to access information about the notification.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(loginViewFetchedUserInfo:)
name:FBSDKProfileDidChangeNotification
nil];
For example, if the notification was posted with a userInfo dictionary
NSDictionary *userInfo = #{#"Blah" : #"foo"};
[[NSNotificationCenter defaultCenter] postNotificationName:FBSDKProfileDidChangeNotification object:self userInfo:userInfo];
and you wanted to access userInfo in the method. You can also access the sender of the notification, which would be the notification's object.
- (void)loginViewFetchedUserInfo:(NSNotification *)notification
{
NSDictionary *userInfo = notification.userInfo;
NSObject *sender = notification.object;
}

NSNotificationCenter defaultCenter iOS 8. Notification is not being delivered to one of observers

Prior iOS 8 all works fine. The problem is:
I have two observers in different classes:
class1:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(didFinishParseUser:)
name:USERS_LOADED_NOTIFICATION_ID object:nil];
class2:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(didFinishParseUser:)
name:USERS_LOADED_NOTIFICATION_ID object:nil];
and notification is posted in some other place:
[FBRequestConnection startWithGraphPath:#"me/friends?fields=id,first_name,last_name,picture.type(small)" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
[[NSNotificationCenter defaultCenter] postNotificationName:USERS_LOADED_NOTIFICATION_ID object:nil userInfo:[NSDictionary dictionaryWithObjectsAndKeys: currentUser, #"user", friends, #"friends", nil]];
} else {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
}
}];
addObserver method is called for both of mentioned classes, however notification is being delivered just to one observer. If I delete this observer(which receives the notification), then another one receives the notification.
Prior to iOS 8 both observers receive the notification.
Can you, please, help me with this issue?
Found answer.
There is another way in iOS 8 to register for receiving remote notifications. I get nil for device token and app break on line:
NSDictionary *item = #{UID_ID : sCurrentUserId, #"deviceToken": appDelegate.deviceToken, #"handle": #"", #"friends": friends};
and second observer never receives notification.
You need to register your NSNotifications to work on iOS 8 and later but don't need to register if your iOS version is less than iOS 8.
Use Following Code
NSArray *vComp = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:#"."];
if ([[vComp objectAtIndex:0] intValue] >= 8) {
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound|UIUserNotificationActivationModeBackground categories:nil]];
}
happy Coding

Getting MAC address of a bluetooth using BluetoothManager private framework

I'm trying to implement device discovery using bluetooth in IOS 5.0.1 iPhone 4S.
I'm using the private framework BluetoothManager.
My code is:
- (IBAction)searchForDevices:(id)sender
{
[self.indicator setHidden:NO];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(bluetoothAvailabilityChanged:) name:#"BluetoothAvailabilityChangedNotification" object:nil];
btCont = [BluetoothManager sharedInstance];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(deviceDiscovered:) name:#"BluetoothDeviceDiscoveredNotification" object:nil];
}
- (void)bluetoothAvailabilityChanged:(NSNotification *)notification
{
self.label.text = #"Availability changed!";
[btCont setDeviceScanningEnabled:YES];
}
- (void)deviceDiscovered:(BluetoothDevice *)device
{
[self.indicator setHidden:YES];
self.label.text = device.address;
My bluetooth headset is discovered.
deviceDiscovered callback function is called,
but device.address does NOT contain the MAC address of the bluetooth device. The app is crashing.
Also, device.name return the name of the notification (BluetoothDeviceDiscoveredNotification) instead of the name of the device discovered.
Any suggestions how can I retrieve the MAC address of my bluetooth headset this way?
use this code:
- (void)deviceDiscovered:(NSNotification *) notification {
BluetoothDevice *bt = [notification object];
NSLog(#"name: %# address: %#",bt.name, bt.address);
If this is a jailbreak app, you can use the key kLockdownBluetoothAddressKey via liblockdown.dylib

Resources