iOS Question Cancel single future local notification

OliverA

Expert
Licensed User
Longtime User
How does one cancel as single local notification that has been set for some time in the future? For example, I'm setting a "Time's up" notification system, where, depending on how long a task lasts, a user is reminded that at various periods on how much time is left. Currently I'm setting the notifications to 30, 20, 10, 5 and 0 minutes left. Now, lets say I set up a task that takes 1 hour to complete and set up the 5 remaining time notifications. Now I would like to cancel just the 30 minute reminder. How do I do that? I tried the notifications cancel method, but that does not do it. Then I tried cancelLocalNotification as detailed in a stackoverflow article, but that just blows up.

B4X:
Sub btnCancelEvent_Click
    Dim callee As Button = Sender
    Log(callee.Text)

'    Dim bagdeNumber() As Int
'    For Each ln As Notification In App.GetScheduledNotifications
'        bagdeNumber = callee.Tag
'        If ln.IconBadgeNumber = bagdeNumber(0) Then
'            ln.Cancel        
'        End If
'    Next
    For x = 0 To buttons.Length - 2
        If callee = buttons(x) Then
            Log("found button")
            callee.Enabled = False
            Dim ln As Notification = alerts(x)
            If x Mod 2 = 1 Then
                ln.Cancel ' Does not cancel notification
                'ln.Register ' OK. I got desperate here
            Else
                Dim no1 As NativeObject = App
                Dim no2 As NativeObject = ln
                no1.RunMethod("cancelLocalNotification", Array (no2)) ' blows up!!!!!
                'Method not found: cancelLocalNotification, target: <UIApplication: 0x133904800>
            End If
            
            Exit
        End If
    Next
    updateUI
End Sub

P.S.: Attaching project

Link(s):
Stackoverflow: https://stackoverflow.com/questions/6340664/delete-a-particular-local-notification
 

Attachments

  • CancelLocalNotifications.zip
    64.8 KB · Views: 281
Cookies are required to use this site. You must accept them to continue using the site. Learn more…