Unsubscribe notification - bluetooth-lowenergy

With the help of a button, the user can receive notifications of a characteristic. The following code will be executed:
connection.setupNotification(setDescriptorEnableNotification(tmpCharacterostoc, connection))
.flatMap(notificationObservable -> notificationObservable)
.observeOn(Schedulers.io())
.subscribeOn(Schedulers.io())
.subscribe(bytes ->
//data processing
);
If the user clicks on the button again, the notification should be unsubscribed, so that no notifications are received.
How can i do this?
I have tried to set the value of the Descriptor to BluetoothGattDescriptor. DISABLE_NOTIFICATION_VALUE but it doesn't work.

The subscribe method returns a Subscription, hold its instance and when you’re no longer interested in notification just call ‘unsubscribe’ on it.
The library will disable notifications for you.

Related

How do I send push notifications with expo and react native?

I am writing a simple app, where I need to send push notifications. For instance, a user liked a post -> send a push notification; or a user commented under a post -> send a push notification; or a user sent you a message -> send a push notification.
I am using Notifications from expo-notifications. I have set up my Notifications.addNotificationReceivedListener and Notifications.addNotificationResponseReceivedListener. I tested them using Expo's push notification tool and it all works fine.
However, I am struggling to send notifications. As suggested per expo's docs they have a library for Node.js called expo-server-sdk-node which takes care of sending notifications. As per their doc:
The Expo push notification service accepts batches of notifications
so that you don't need to send 1000 requests to send 1000
notifications. We recommend you batch your notifications to reduce
the number of requests and to compress them (notifications with
similar content will get compressed).
And I agree with the above statement. Sending notifications on batch makes sense, however, I have a question regarding this:
How do I implement it? Do I keep counter on the user's notification, and lets say, the user has liked 10 posts -> then I send 10 notifications as a batch request? What if they liked 8 posts and then closed the app? Do I send the notifications on closing the app? It doesn't seem right to me. Also, if the user has sent a message, I believe I should straight away send the notification, rather than waiting for a batch request for the user to send 10 messages.
The implementation they offer on their docs is the following:
// Create the messages that you want to send to clients
let messages = [];
for (let pushToken of somePushTokens) {
// Each push token looks like ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]
// Check that all your push tokens appear to be valid Expo push tokens
if (!Expo.isExpoPushToken(pushToken)) {
console.error(`Push token ${pushToken} is not a valid Expo push token`);
continue;
}
// Construct a message (see https://docs.expo.io/push-notifications/sending-notifications/)
messages.push({
to: pushToken,
sound: 'default',
body: 'This is a test notification',
data: { withSome: 'data' },
})
}
Which is OK and understandable. But then I struggle with the next step:
let chunks = expo.chunkPushNotifications(messages);
let tickets = [];
(async () => {
for (let chunk of chunks) {
try {
let ticketChunk = await expo.sendPushNotificationsAsync(chunk);
console.log(ticketChunk);
tickets.push(...ticketChunk);
} catch (error) {
console.error(error);
}
}
})();
That is, at which point do I call expo.chunkPushNotifications(messages) and then await expo.sendPushNotificationsAsync(chunk). Do I wait 10 similar notifications to be collected, do I wait some time, do I do it when the user closes the app, or something else?

Can you expire / remove a message remotely on FCM?

I'm using FCM for my push messages. Its great, however I've a client that needs to be able to remove a push message once its sent - (in case of mistakes / typos etc).
I know you can get the message id from when the Topic is queued to send messages, just wondering if there is a way to then use that ID to expire those messages remotely. i.e. to delete the message.
There is currently no way to delete/remove a message from the server side/console. The message_id is just an identifier that the message was sent successfully to the FCM server.
What is usually used for this scenario is the tag parameter (see my answer here) where an existing notification with the same tag gets replaced with the newer one.
There are scenarios where you might want a replacing notification to notify the user rather than silently update. Chat applications are a good example. In this case you should set tag and renotify to true.
write this code on your sw.js
const title = 'Notification 2 of 2';
const options = {
tag: 'renotify',
renotify: true
};
registration.showNotification(title, options);
You can test demo on here by clicking in renotify button

How to receive the background notification in iOS 10?

Description - Uptil iOS 9, following method gets called
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
But from iOS 10, apple provide new framework i.e userNotification.framework
and new methods to handle i.e
// The method will be called on the delegate only if the application is in the foreground. If the method is not implemented or the handler is not called in a timely manner then the notification will not be presented. The application can choose to have the notification presented as a sound, badge, alert and/or in the notification list. This decision should be based on whether the information in the notification is otherwise visible to the user.
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
and
// The method will be called on the delegate when the user responded to the notification by opening the application, dismissing the notification or choosing a UNNotificationAction. The delegate must be set before the application returns from applicationDidFinishLaunching:.
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler
But Now I am not able to get the notification call back when app is in background and user not clicked on notification.
What I want is when user is in background and if he received any notification then in which method I will get the call back of received notification.
Thanks in advance.
In iOS10, willPresent will be called when app is running foreground. didReceive will be called when user tap the notification while app is running background.
If you want handle notifications when app is running background, you still need to implement didReceiveRemoteNotification...fetchCompletionHandler, and don't forget to add "content-available" to your notification payload. Set it to 1.

Can I add elements to the aps payload sent by the Bluemix IBM Push Notifications service?

I'm successfully using Bluemix Push to send notifications via the REST interface to an iOS app with a simple string alert message. That works fine.
Now I would like to send a more complex message where alert is a dictionary and has a sibling "category" element per The Remote Notification Payload.
Is this possible with Bluemix Push? Whenever I try to deviate from the basic structure, I get "Bad Request - Invalid JSON".
After much head-scratching, I finally picked up a hint from https://www.ng.bluemix.net/docs/services/mobilepush/t_advanced_notifications.html#t_push_badge_sound_payload and figured out that since the category field is unique to APNS, what I needed to send is
"settings" : {
"apns" : {
"category" : "myCategory"
}
#DSchultz_mo I was having issues to find the documentation but I finally found it, so if you go to https://mobile.ng.bluemix.net/imfpushrestapidocs/#/ you can use swagger to register your device and send notification and the magic button is in model there is more details for sendMessageBody

Push Notifications on iPhone without alerts to the user

I have searched the web on my question but did not find anyone answering it. This looks weird as I am sure other people face similar issue.
At the moment my app is receiving push notification fine. I have a chat module where user can speak and whenever a new message is being sent, the other phone receive a push notification to update the chat.
You could say no issue there, but the problem is when the user is out of the application: he is still receiving those notifications showing a banner on the screen, and I want to dis-activate this. Basically I want push notification without alerts to the user. Is there a way to do that?
Thanks
Just leave the sound property of your push notification payload empty, omit the alert/text property and add "content-available":1 and your notification will be silent. This is often referred to as silent push notification or "push-to-sync".
See documentation here:
For a push notification to trigger a download operation, the
notification’s payload must include the content-available key with its
value set to 1. When that key is present, the system wakes the app in
the background (or launches it into the background) and calls the app
delegate’s
application:didReceiveRemoteNotification:fetchCompletionHandler:
method. Your implementation of that method should download the
relevant content and integrate it into your app
So your payload should least look like this:
{
"aps" : {
"content-available" : 1,
"sound" : ""
},
"chat-message" : "Hello World!"
}

Resources