BIBD
BIBD

Reputation: 15414

How can I get firemonkey to display a local notification on iOS?

I've pulled the following code from Embarcadero site (here) to generate a local notification.

procedure TForm1.SetNumberClick(Sender: TObject);
var
  MyNotification: TNotification;
begin
  // Create an instance of TNotification
  MyNotification := NotificationCenter1.CreateNotification;
  try
      MyNotification.Number :=18;
      MyNotification.AlertBody := 'Delphi for your mobile device is here!';
      NotificationCenter1.PresentNotification(MyNotification);
  finally
    MyNotification.DisposeOf;
  end;
end;

It compiles and runs. As expected, I did have to create NotificationCenter1 as a TNotificationCenter on my form. It works find under Android, but under iOS I get butkus. No local notification, no count on the icon, not even an error.

Did it ever work under XE8?

Has something changed with respect to local notification between XE8 and 10/Seattle?

My phone is running iOS 9.2. Did something change in iOS between 8.x and 9.x that breaks local notifications for Firemonkey?

Upvotes: 0

Views: 1675

Answers (2)

BIBD
BIBD

Reputation: 15414

The ultimate solution was two fold:

  1. You must have FMLocalNotificationPermission set to true (Project -> Options -> Version Info)
  2. The notifications will only show up if the app is NOT running in the foreground (e.g., you've gone back to you home screen, shut down the application, etc.). This is with both the ScheduleNotification and PresentNotification methods.

Upvotes: 1

Jim McKeeth
Jim McKeeth

Reputation: 38743

I've followed the tutorial before, and it works.

There are also two sample apps that ship with with 10 Seattle.

I just tried both of these on iOS 9.2 with Delphi 10 Seattle Update 1, and they worked as expected for me. (Also worked in XE8). Your code looks correct as well.

Maybe at some point you told iOS not to show you notifications. Did you check in application settings?

Upvotes: 1

Related Questions