iOS Question Trouble with launching MessageComposer

Haris Hafeez

Active Member
Licensed User
Longtime User
Hello Everyone,

I have run into a rather strange error, which I'm quite sure has to do with me missing something.

I am trying to launch the MessageComposer when the user clicks on a local notification. The errors I get in the log are:

Application_Start
Application_Active
Class (b4i_customlistview) instance released.
Application_Inactive
Application_Background
Application_Receivelocalnotification
Application_Foreground
Application_Active
<CKSMSComposeRemoteViewController: 0x1475eea0> timed out waiting for fence barrier from com.apple.mobilesms.compose
MC Result = 0
Warning: Attempt to dismiss from view controller <UINavigationController: 0x14549830> while a presentation or dismiss is in progress!

Any tips on how to resolve this please?

Many thanks.
 

Haris Hafeez

Active Member
Licensed User
Longtime User
Thanks for your reply. I managed to get the notification working by moving the code around a bit. However, the issue I now get is that the notification tag is always nil. Will appreciate help with this. The CustomListView was always a global, I wonder why its claiming to release it.

So the code is like this:
B4X:
Private Sub Application_Active

    If IsLaunchedFromNotification Then
        If Not(ScheduledMessagesPage.Visible) Then 'bring this page to the top before attempting to set it as a parent of messagecomposer
            NavControl.ShowPage(ScheduledMessagesPage)
        End If
        Log("Notification.Tag = " & LaunchingNotification.Tag) 'prints nil
        HandleTextNotificationLaunch(LaunchingNotification.Tag)
        LaunchingNotification.Cancel
    End If
End Sub

Sub Application_ReceiveLocalNotification (LN As Notification)
    'this event will fire if the scheduled notification happend when the app was running
    Log("launched while app is running. LN.TAG = " & LN.Tag) 'prints nil
    IsLaunchedFromNotification = True
    LaunchingNotification = LN
End Sub
........

Sub HandleTextNotificationLaunch(key As String)
    Dim mc As MessageComposer
    mc.Initialize("MessageComposer")
    If mc.CanSendText Then
        Log("Before getting pending message. key: " & key) 'prints nil
        Dim pm As PendingMessage = MessageStore.GetSavedMessage(key) 'fails here
        Log("Composing text: " & pm.StrMessage & ", to: " & pm.StrTo)
        mc.SetRecipients(Array As String(pm.StrTo))
        'mc.SetRecipients(Array As String("Haris"))
        mc.Body = pm.StrMessage
        'mc.Body = "Test message body"
        mc.Show(ScheduledMessagesPage)
    Else
        Log("Can't send TEXTS :(")
    End If
End Sub

The code that sets the notification is:

B4X:
Sub ScheduleLocalNotificationForMessage(key As String)
    Dim n As Notification
    Dim pm As PendingMessage = MessageStore.GetSavedMessage(key)
    DateTime.TimeFormat = "HH:mm"
    Dim ticks As Long = DateTime.DateTimeParse(pm.Date,pm.Time)
    n.Initialize(ticks)
    n.AlertBody = "Would you like to send the scheduled message to " & pm.StrTo &"?"
    n.Tag = key
    n.PlaySound = True
    n.Register
End Sub
 
Upvote 0

Haris Hafeez

Active Member
Licensed User
Longtime User
The Tag will be empty. The tag information is not added to the notification object that the system creates.
So how do we determine what action to take based on a notification? It seems that I will have encode some information in the notification itself.

Thanks.
 
Upvote 0
Top