iOS delayed notification only fires if app closed (FMX) - firemonkey

Based on this Embarcadero example I have the following code in a TButton click in FMX app for iOS. Supposed to pop up a notification after 10 seconds.
void __fastcall TForm1::ScheduleNotificationButtonClick(TObject *Sender)
{
if (NotificationCenter1->Supported()) {
TNotification *myNotification = NotificationCenter1->CreateNotification();
__try {
myNotification->Name = "MyNotification";
myNotification->AlertBody = "C++ for your mobile device is here!";
// Fire in 10 seconds
myNotification->FireDate = Now() + EncodeTime(0, 0, 10, 0);
// Send notification to the notification center
NotificationCenter1->ScheduleNotification(myNotification);
}
__finally {
myNotification->DisposeOf();
}
}
}
When i click the button nothing happens. But, I accidentally figured out that i can make it fire by closing the app AFTER clicking the button. If i click the button and then close the app, sure enough, at 10 seconds the notification pops up. What could possibly be suppressing the notification from firing while the app is running?
p.s. This is related to my earlier post but this is unique enough i thought clearer to make separate post.

Related

Prompts on top of popup windows in Xamarin and MAUI

I have discovered the limitation of displaying prompts when they are invoked from a popup window. Specifically verified with CommunityToolkit.Maui Popups.
Here's the details:
In the Map page I have this handler for the map clicked event:
void mapClicked(object sender, MapClickedEventArgs e) {
var pin = new Pin {
Label = "Here's where it is",
Location = e.Location
};
map.Pins.Add(pin);
}
I wanted to allow the user to edit the pin label when clicking on the it, like so:
pin.InfoWindowClicked += async (s, args) => {
string pinName = ((Pin)s).Label;
await DisplayPromptAsync("Enter new label", "enter new label");
};
However, this didn't work as no DisplayPrompt was shown. I tried running it in the main thread, to no avail either.
UPDATE. I've figured it out, see answer below.
The problem arises when attempting to bring up the prompt from a popup window. Evidently, one can't have a DisplayPromptAsync (or DisplayAlert for that matter) on top of a popup.
On a platform-specific level in iOS the error message reads:
Attempt to present <UIAlertController> on <Microsoft_Maui_Controls_Platform_Compatibility_ShellFlyoutRenderer> (from <Microsoft_Maui_Controls_Platform_Compatibility_ShellFlyoutRenderer>) which is already presenting <CommunityToolkit_Maui_Core_Views_MauiPopup>.

iOS notifications sporadic (FMX)

Following the Embarcadero docs at this link i'm testing notifications on iOS (in FMX app built with C++). I've done the follownig:
Added #include <System.Notification.hpp> to the header file
Set FMLocalNotificationPermission to true
Dropped TNotificationCenter component on the form
Then, i put the following code in a button click:
void __fastcall TForm1::ScheduleNotificationClick(TObject *Sender)
{
if (NotificationCenter1->Supported()) {
TNotification *myNotification = NotificationCenter1->CreateNotification();
__try {
myNotification->Name = "MyNotification";
myNotification->AlertBody = "C++ for your mobile device is here!";
// Fire in 10 seconds
myNotification->FireDate = Now() + EncodeTime(0, 0, 10, 0);
// Send notification to the notification center
NotificationCenter1->ScheduleNotification(myNotification);
}
__finally {
myNotification->DisposeOf();
}
}
}
Once in a while it works...but rarely and never more than once. Most of the time it doesn't at all (repeated deleting and reinstall of app).
Next, i tried the "Present the Notification Message Immediately" code they provide:
void __fastcall TForm1::PresentNotificationClick(TObject *Sender)
{
if (NotificationCenter1->Supported()) {
TNotification *myNotification = NotificationCenter1->CreateNotification();
__try {
myNotification->Name = "MyNotification";
myNotification->AlertBody = "C++ for your mobile device is here!";
// Set Icon Badge Number (for iOS) or message number (for Android) as well
myNotification->Number = 18;
myNotification->EnableSound = False;
// Send notification to the notification center
NotificationCenter1->PresentNotification(myNotification);
}
__finally {
myNotification->DisposeOf();
}
}
}
Nothing happens at all with this code. I've tried this from scratch several times and i'm as sure as i can be that i'm coding it per their examples. I'm using 10.3 (Embarcadero® C++Builder 10.3 Version 26.0.32429.4364). I would think my code has a problem except once in blue moon it works.
My target is iPhone running 12.1.4 and i've tried building with SDK11.4 and SDK12.0, no difference. When i first run app i get the "allow or don't allow" popup and my app subsequently shows up in the Notification settings - just doesn't work.
russ
UPDATE 3-25-2019: If I run that top block of code (from a button click on iPhone) it will now run everytime - but ONLY IF i immediately kill the app after clicking. 10 seconds later it fires the notification. Why won't the notification appear if i leave my app running??
Are you sure you are calling "PresentNotificationClick" from the TButton when you click it?

Multiple leave events generated in Custom widget in Qt

I receive a Leave Event every time i move a pixel with my mouse over a customized QFrame i did. Why is this happening?.
I reimplemmented the leave and enter event as follows. As you can see i tried to comment the QFrame enterEvent, and restrict the repetition with a boolean, but it doesnt work because an enter and leave are continuously generated:
void enterEvent( QEvent *event ){
//QFrame::enterEvent(event);
if (!mouseHover_)
{
mouseHover_ = true;
emit hoverInSignal("");
}
}
void leaveEvent( QEvent *event ){
//QFrame::leaveEvent(event);
if (mouseHover_)
{
SmartUIWrapper::Instance()->addInfoMessage("out");
emit hoverOutSignal();
mouseHover_ = false;
}
}
Does it have something to be with the focus?
I discovered the reason.
I created a panel over this QFrame when i hovered.
When i moved the mouse, since the panel is positioned on the right bottom side of the cursor position, everytime i moved over the QFrame to the right or bottom, when i hovered this new panel i created, it looses the focus, so it gets closed again, then another hover comes, and then it´s created again... and again... everytime i hover the new panel.

WP7 PhoneGap application back button exiting application

I am working on WP7 Phonegap app. I have used below code to handle back button, but whenever I click back button , back button event is not cancelled and application gets exited.
void OnBackKeyPressed(object sender, CancelEventArgs e)
{
var result = MessageBox.Show("Dof fd fd you want to exit?", "Attention!",
MessageBoxButton.OKCancel);
if (result == MessageBoxResult.OK)
{
// Do not cancel navigation
return;
}
e.Cancel = true;
}
Please helpme on same.
Thanks in advance.
One of the lead devs for the Windows Phone implementation of PhoneGap recently wrote about correctly handling the back button.
See his article at http://www.risingj.com/archives/493

WP7 MessageBox stops vibrate from happening when displayed

I am having some trouble getting my application to cause the phone to vibrate and play a sound at the same time as displaying a messagebox.
I have managed to get the sound to repeat whilst the messagebox is displayed but I cannot get the vibrate to work at the same time as a messagebox.
I currently use the following code to play a vibrating pulse:
public void vibrate()
{
DispatcherTimer vibrateTimer = new DispatcherTimer();
vibrateTimer.Tick += new EventHandler(vibrateTimer_Tick);
vibrateTimer.Interval = new TimeSpan(0, 0, 1);
vibrateTimer.Start();
}
void vibrateTimer_Tick(object sender, EventArgs e)
{
vc.Start(TimeSpan.FromMilliseconds(300));
}
I then call the vibrate() method. If I call a simple vibrate that plays for say 10 seconds without pulsing then this works however the pulse does not.
Is there anyway around this so I can play a pulsing vibrate while the message box has been displayed?
Thanks
You can use XNA's Guide.BeginShowMessageBox as the message box instead. I believe this doesn't vibrate or play a sound, so you should have full control.

Resources