0

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?

BIBD
  • 15,107
  • 25
  • 85
  • 137

2 Answers2

1

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?

Jim McKeeth
  • 38,225
  • 23
  • 120
  • 194
  • Got it, other apps let notifications through so iOS config wasn't the problem. I also thought it might have been buried in entitlements. However, it seems to be in the logical and consistent location "Project -> Options -> Version Info" :^) – BIBD Jan 18 '16 at 17:44
1

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.
BIBD
  • 15,107
  • 25
  • 85
  • 137
  • You do need `FMLocalNotificationPermission` set to true (it is in the tutorial too), but the app doesn't need to be running. You can even reboot and the notification will still get delivered. – Jim McKeeth Jan 18 '16 at 19:39
  • Correct, by default, iOS won't show the notification if your app is in the foreground, but I think you can change that in the notification settings. – Jim McKeeth Jan 18 '16 at 19:42