I am developing a Bluetooth Low Energy (4.0) device that works with an iOS app and uses CoreBluetooth. I have successfully created this app and it interacts with the device just fine. However, now that iOS 8 allows developers to implement custom widgets, I want to display a "Disconnect" button in the UINotification "Today" Center.
The issue is this: I believe I have read that there is no way to communicate between the widget and the app meaning that the widget has it's own container. This also means then that I cannot access the Bluetooth object in the app that is holding the reference to my Bluetooth device from the widget itself in order to disconnect the object. I am able to create a new Bluetooth object inside the widget class and retrieve the bluetooth connection from the iOS system but even I disconnected the BT device at this point, it would still be holding a reference inside the app.
Can anyone offer any insight on wonder what I am trying to do is possible?
You could possibly use a shared NSUserDefaults database to transfer data between your app and extension. You may also be interested in NSUserDefaults key value observing.
App extensions are meant to be independent from their containing app, and I'm not sure they were meant for this purpose.
However, another option would be to implement a custom URL scheme for your containing app, and then to use openURL to open your containing app and execute a disconnect action (or anything else you'd like your extension to do).
Related
I am trying to implement communication between WearOs watch and Android phone Apps. Here is the key point is between Apps, not between Devices because for me important is that, i can get the information about if the watch app is connected with the Phone app and vice versa. But it seems that On Android and WearOs, it happens on device level.
I have implemented WearableListenerService on both side and works perfectly fine. OnCapabilityChanged is fired as well but problem with the OnCapabilityChanged method is only fired if connection is lost and connected again. It is not fired when phone and watch are already connected and when I start the app on the phone, I am not able to know if there is already connection.
OnPeerConnected seems to be a good candidate in this sense but it is deprecated and never fired.
What is the best way to get this information? I have tried also Activity level CapabilityClient.IOnCapabilityChangedListener on MainActivity but OnCapabilityChanged behavior seems to be exactly the same. It is not called when the activity is started.
I have tried to implement code below also in OnResume but it returns always null.
var capabilityInfo = capabilityClient
.GetCapability(capability_wear, CapabilityClient.FilterReachable);
capabilityInfo.AddOnSuccessListener(this);
public async void OnSuccess(Java.Lang.Object capabilityInfo)
{
}
Beside this question, related question, is it even possible to disconnect phone app to watch apps?
I have had similar experience on Tizen watches and There is a SocketService with Connect and Close endpoints implements. Simply can be connected between Apps. But here on WearOs, it seems to happen on Device level only.
What's your definition of "watch app is connected"?
The Node (device) is connected and the app is installed? Or do you mean the app is running.
If you just mean app installed and device connected, then your code should work. Are you using a custom capability that your app declares? That should prove it is your app installed and not just the device connected.
File a bug using a reproduction in the https://github.com/android/wear-os-samples/tree/main/DataLayer project. https://issuetracker.google.com/issues/new?component=1065087&template=1592236
https://developer.android.com/training/wearables/data/data-layer
The CapabilityClient provides information on which Nodes on the Wear OS network support which custom app capabilities.
If you mean connected as in both running simultaneously then you would probably use ChannelClient, MessageClient, or DataClient to send observable updates. But this should generally be careful how you do that as you shouldn't try to maintain a live connection, say using the ChannelClient, between your watch and mobile apps. It will waste battery on both sides and there are hopefully more efficient patterns to achieve whatever you are trying to do.
I'm working on an iPhone app to control some custom BLE hardware. I am able to talk to my device and generate all required controls, but my problem now comes with setting up UserNotifications.
Part of the functionality of this device is to alert the user if one of the BLE characteristic values gets outside of a certain range. When the app is in focus, I am able to do this via UIAlerts. I have played with UserNotifications and I can trigger a notification while the app is focused so that the notification will appear after a specific interval. My issue is trying to generate a UserNotification based on data that's coming over a BLE connection in an app that's not focused.
I can tell via LED's on my hardware that the BLE connection is being maintained even while I'm out of focus/locked. Is there a way to evaluate data from a background BLE connection and create a UserNotification based on it?
I found This Question on StackExchange asking basically the same thing, but I'm hoping that several years later there may be more answers out there.
Cheers,
Roger
Paulw11 above mentioned the app being set up for background operation, which I was not aware of (I'm really new to IOS, I'm more of a low-level firmware guy).
It was just a matter of setting up Xcode background mode to let this run in the background, now I can alert the user regardless of whether the app is Active or Background.
I am writing an iOS app that communicates with a BLE device that we are developing. Most communication does not require bonding, but there are some secure features where bonding will be required. I've put those secure features in a separate service which has been flagged as requiring bonding, and when I try to access that service iOS correctly starts the bonding process.
The problem I'm having, is that I want to be able to control exactly when this bonding takes place so I can design my UI appropriately. Most of the time, iOS waits until I try to access the secure service before it starts the bonding process, but I have also seen the bonding dialog appear shortly after I call CBPeripheral.DiscoverCharacteristics() and long before I actually use the secure service for anything. The bonding dialog seems to appear later if I'm re-running the app when I've already bonded once and then deleted the bonding both in iOS and the remote BLE device.
I'm guessing that iOS is caching the service/characteristic information, so after the first connection when I call CBPeripheral.DiscoverCharacteristics() it's not actually communicating with the remote BLE device, and thus isn't triggering the need to bond.
There's a discussion about how to clear the bluetooth cache on OSX, but nothing similar for iOS. I've tried this:
Unbond device in iOS
Turn off Bluetooth
Turn off iPad
Turn iPad back on
Turn Bluetooth back on
But the bonding request dialog still comes later, which I'm guessing means the cache didn't actually get cleared.
If the devices are unbonded and the peripheral sends an SMP "Security Request", it will show the popup.
It also shows it when you try to interact with a protected characteristic.
My scenario is:
Another (whatever app it is) try to retrieve the value from a Bluetooth device, But Bluetooth device doesn't send data other than our application.
Another application wants Bluetooth data it needs to call our app in background mode to perform an operation also in the background.
In short:
Retrieve data from Bluetooth in the background and share that content to another application.
If I tried using Custom URL it's open our application into the foreground. So, this one not covers our expectation.
Is that possible with Widget kind of? or any other method.
If any info missed let me know to understand my scenario.
I have a fitness app that is already in the app store and now I want to implement a bluetooth device that users can purchase if they wish. This is my first time dealing with bluetooth and after reading "Core Bluetooth Programming Guide", I have the following questions.
My app contains information that my bluetooth device requires simply to display the data. If I'm not mistaken, this makes the app the "Peripheral" because it has the data. The bluetooth device wants the data from the app so that makes the bluetooth device the "Central". Am I correct about this?
Finally, here is where I get confused. The bluetooth device has a button that I want when pressed to trigger the app to get the app to send new values to the bluetooth device. Is this possible? The reason I ask because in this scenario, would this now mean that the bluetooth device is the peripheral and the app is the central? If yes, will I have to break the current connection between the two in order to switch their roles (manager, and peripheral)?
Thank you in advance, really appreciate it!
Ted
As you have control over coding the app and coding the device, you can make it work either way around (Assuming the device is to be used specifically with your app and nothing else).
Both central and peripheral have methods to read and write data from/to the peripheral.
Without more information on the data and how often it's updated, it's difficult to suggest the best way to do it.
You say your device will have a button that will tell the app to send data over to it, well the app won't need to send anything it simply keeps values up to date then your button would tell your device to read the latest value.
Or (Again without knowing the purpose this may not suit) you do away with the button completely and your device subscribes to a characteristic in the app and is notified every time the value is changed by the app.