iOS Question Enable/Disable Firebase Push Notifications by User

aminoacid

Active Member
Licensed User
Longtime User
I am using Firebase notifications in one of my B4I and B4A Apps and they work very well. The code is based on the example posted by Erel:


But now I'm trying to figure out a way in which the user can temporarily "mute" the notifications and then "unmute" them as needed. I can't seem to find any way in the example above (the B4I part) that will allow me to add or modify the code to temporarily disable notifications and then re-enable them. I realize that iOS apps don't run in the background, but I have seen other iOS apps that will allow you to temporarily mute these notifications when too many have been received without having to do so in the main phone Settings.

Has anyone accomplished this? Any ideas or suggestions? ...... Thanks!
 
Solution
If you are sending the notification using topic then you can let your user to unsubscribe it by unchecking on a checkbox in setting page of your app.

When they want to reenable back the notification, they will just need to check on the same checkbox to subscribe to the same topic.

ddefrain

Member
Licensed User
Longtime User
I am using Firebase notifications in one of my B4I and B4A Apps and they work very well. The code is based on the example posted by Erel:


But now I'm trying to figure out a way in which the user can temporarily "mute" the notifications and then "unmute" them as needed. I can't seem to find any way in the example above (the B4I part) that will allow me to add or modify the code to temporarily disable notifications and then re-enable them. I realize that iOS apps don't run in the background, but I have seen other iOS apps that will allow you to temporarily mute these notifications when too many have been received without having to do so in the main phone Settings.

Has anyone accomplished this? Any ideas or suggestions? ...... Thanks!

If you handle a flag?
If it is enabled allow the receive notification, in the other hand not
I use KeyValuestore to store/retrieve the flag

I realize that iOS apps don't run in the background
Yes they Do
 
Upvote 0

aminoacid

Active Member
Licensed User
Longtime User
If you handle a flag?
If it is enabled allow the receive notification, in the other hand not
I use KeyValuestore to store/retrieve the flag

Yes.. correct. However, how do you programmatically suppress or allow the notifications. The firebase events in the example don't fire when a notification is to be sent out. There may be other events that I am not aware of - - - -
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
If you are sending the notification using topic then you can let your user to unsubscribe it by unchecking on a checkbox in setting page of your app.

When they want to reenable back the notification, they will just need to check on the same checkbox to subscribe to the same topic.
 
Upvote 1
Solution

aminoacid

Active Member
Licensed User
Longtime User
You may click on the checkmark at the side of my answer to mark as solution.

Yes... as soon as I try it out and make sure that it works. Thanks!

Edit:

Yes, this works perfectly. Here are the details in case anyone else needs to do this in B4I:

Referring to the link to Erel's example in Post#1

1. Added a checkbox in designer - "chkMute"

2. Added the following Sub in module - "FirebaseMessaging"

B4X:
Public Sub UnSubscribe (Topics() As Object)
    For Each topic As String In Topics
        fm.UnsubscribeFromTopic("ios_" & topic)
    Next
End Sub

3. Added the following Sub in module - "B4XMainPage"

B4X:
Private Sub chkMute_CheckedChange(Checked As Boolean)
    If Checked Then
        CallSub2(FirebaseMessaging, "UnSubscribe", Array("general"))
    Else
        CallSub2(FirebaseMessaging, "SubscribeToTopics", Array("general"))
    End If
End Sub
 
Last edited:
Upvote 0

aeric

Expert
Licensed User
Longtime User
I thought on the opposite way which is instead: check to receive notification, uncheck to stop receiving notification. 😄
You may have more than one checkboxes with different topics.
e.g
✅ I want to receive notification on product updates
✅ I want to receive notification on promotions
✅ I want to receive notification on new messages

But it is not right or wrong. Just how the way you design your app.
 
Upvote 0

aminoacid

Active Member
Licensed User
Longtime User
I thought on the opposite way which is instead: check to receive notification, uncheck to stop receiving notification. 😄
You may have more than one checkboxes with different topics.
e.g
✅ I want to receive notification on product updates
✅ I want to receive notification on promotions
✅ I want to receive notification on new messages

But it is not right or wrong. Just how the way you design your app.

Correct - I designed it as a "Mute" check box. So when checked, notifications are muted. In my app, the notifications are for an alarm.

My goal is to temporarily mute notifications for the next (say) 10 notifications and then automatically unmute them. That way the user is not bothered with continuous notifications for a while. But in case he/she forgets to turn them back on, it does it automatically.

Now I need to figure out how to count the notifications ..... but that's another story ...... 😅
 
Upvote 0

aminoacid

Active Member
Licensed User
Longtime User
But isn't it not nice to auto enable the notification (without their consent or knowledge)? Unless you have put a message informing them about it.

Yeah ... but this is an App that is used "internally" to send an alert for an alarm condition and will not be available to the public. The user's are all known to me (friends/colleagues) and they know I do a lot of things to them without their consent or knowledge ;) They don't care and neither do I. :) The purpose of the notifications is really to drive them crazy until they take action and find out the cause of the alarm and clear it. However they pleaded with me to give them a break while they worked on the situation and so here I am, doing so .... this will make them very happy! :)

Actually, instead of counting the notifications, I'm just going to let them mute the notifications for (say) 4 hours. If the alarm condition is not cleared by then, the notifications will resume and start bugging them again.
 
Upvote 0

ddefrain

Member
Licensed User
Longtime User
If you are sending the notification using topic then you can let your user to unsubscribe it by unchecking on a checkbox in setting page of your app.

When they want to reenable back the notification, they will just need to check on the same checkbox to subscribe to the same topic.
The best way; Thanks aeric
 
Upvote 0
Top