Jump to content
ToddFrankson

Android/IOS push notifications...

Recommended Posts

I have Push Notifications working just fine....... 

What I want to do now is the following:

When the user taps the notification and the App is closed, I want the App to open and display the Notification within the app(in a TText for example). 

My problem seems to be that when the notification is tapped, and the app launches, the notification is cleared before the app can open.

Is there a way to do what I want?   

 

Share this post


Link to post
4 hours ago, ToddFrankson said:

Is there a way to do what I want?

If the app is not already running, you need to handle startup notifications. See part 10 of these instructions, which deals with handling the StartupNotifications property.

Share this post


Link to post
On 12/22/2024 at 3:14 PM, Dave Nottage said:

If the app is not already running, you need to handle startup notifications. See part 10 of these instructions, which deals with handling the StartupNotifications property.

If the App isn't running, and receives the notification, can I, for example, add it to a text file at that point?

Share this post


Link to post
Just now, ToddFrankson said:

If the App isn't running, and receives the notification, can I, for example, add it to a text file at that point?

Yes, however you might want to assess why you need to do this at all.

 

On Android, it's possible to handle a notification in code while the app is not running by using a service, as per the "RelayDemo" in FCMRebooted, except that instead of sending an SMS, the code could store the notification info in a text file as you suggest.

 

On iOS, it's a completely different story - handling notifications in code when the app is not running requires that the notification is "silent" (using a content-available flag in the payload), and even then the OS can be extremely restrictive as to whether it will even execute the code.

  • Like 1

Share this post


Link to post
On 12/29/2024 at 5:12 PM, Dave Nottage said:

Yes, however you might want to assess why you need to do this at all.

 

On Android, it's possible to handle a notification in code while the app is not running by using a service, as per the "RelayDemo" in FCMRebooted, except that instead of sending an SMS, the code could store the notification info in a text file as you suggest.

 

On iOS, it's a completely different story - handling notifications in code when the app is not running requires that the notification is "silent" (using a content-available flag in the payload), and even then the OS can be extremely restrictive as to whether it will even execute the code.

I was looking to keep track of notifications for the user to be able to look back at them.

Share this post


Link to post
On 12/22/2024 at 3:14 PM, Dave Nottage said:

If the app is not already running, you need to handle startup notifications. See part 10 of these instructions, which deals with handling the StartupNotifications property.

@Dave Nottage 

 

I noticed this in the documentation: Note: The push notification title and body are not available in DataObject when the application is launched (coldstart) by tapping the notification in the Notification Center.

 

So there is no way to display the notification, on a cold start, within the App??

 

Share this post


Link to post
31 minutes ago, ToddFrankson said:

So there is no way to display the notification, on a cold start, within the App??

There is on Android if you use the FCM implementation in Kastri, and send a "Data only" notification. By that, I mean the payload needs to look like this, for example:

{
  "message":{
    "topic":"FCMRebooted",
    "data":{
      "title":"Test",
      "body":"Example"
    }
  }
}

Notice that there is no "notification" member. The same applies to when the application is running in the background.

This will not work for the default implementation in Delphi, as it uses FCM's default handling for when the app is not running or in the background, which does not "look for" the data member.

Share this post


Link to post
14 hours ago, Dave Nottage said:

There is on Android if you use the FCM implementation in Kastri, and send a "Data only" notification. By that, I mean the payload needs to look like this, for example:


{
  "message":{
    "topic":"FCMRebooted",
    "data":{
      "title":"Test",
      "body":"Example"
    }
  }
}

Notice that there is no "notification" member. The same applies to when the application is running in the background.

This will not work for the default implementation in Delphi, as it uses FCM's default handling for when the app is not running or in the background, which does not "look for" the data member.

So what does PushService.StartupNotifications contain when the App cold starts?

Share this post


Link to post
3 hours ago, ToddFrankson said:

So what does PushService.StartupNotifications contain when the App cold starts?

From the example message payload, this is the JSON from the DataObject in StartupNotifications:

{
  "google.delivered_priority": "normal",
  "google.sent_time": "1735931915894",
  "google.ttl": "2419200",
  "google.original_priority": "normal",
  "google.product_id": "111881503",
  "body": "Example",
  "from": "\/topics\/FCMRebooted",
  "title": "Test",
  "com.google.firebase.iid.WakeLockHolder.wakefulintent": "true",
  "google.message_id": "0:1735931916503454%e6375accf9fd7ecd",
  "google.c.sender.id": "952580923416"
}

 

Share this post


Link to post
19 hours ago, ToddFrankson said:

@Dave Nottage 

 

I noticed this in the documentation: Note: The push notification title and body are not available in DataObject when the application is launched (coldstart) by tapping the notification in the Notification Center.

 

So there is no way to display the notification, on a cold start, within the App??

 

 

21 minutes ago, Dave Nottage said:

From the example message payload, this is the JSON from the DataObject in StartupNotifications:


{
  "google.delivered_priority": "normal",
  "google.sent_time": "1735931915894",
  "google.ttl": "2419200",
  "google.original_priority": "normal",
  "google.product_id": "111881503",
  "body": "Example",
  "from": "\/topics\/FCMRebooted",
  "title": "Test",
  "com.google.firebase.iid.WakeLockHolder.wakefulintent": "true",
  "google.message_id": "0:1735931916503454%e6375accf9fd7ecd",
  "google.c.sender.id": "952580923416"
}

 

I'm confused now....The Docs say there's no title and body, but you are saying there is, or did you just type the JSON up?  Or was this sent thru FCMRebooted?

 

Share this post


Link to post
Just now, ToddFrankson said:

I'm confused now....The Docs say...

You might have missed this part in my original answer:

18 hours ago, Dave Nottage said:

There is on Android if you use the FCM implementation in Kastri, and send a "Data only" notification

When using the default Delphi implementation, I expect the JSON will be missing the title and body members.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×