iOS notifications sporadic (FMX)

别说谁变了你拦得住时间么 提交于 2019-12-08 11:04:42

问题


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??


回答1:


Are you sure you are calling "PresentNotificationClick" from the TButton when you click it?



来源:https://stackoverflow.com/questions/54895344/ios-notifications-sporadic-fmx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!