iOS通知零星(FMX)

问题描述 投票:0回答:1

继Embarcadero docs at this link之后,我正在测试iOS上的通知(在使用C ++构建的FMX应用程序中)。我做了以下跟进:

  • #include <System.Notification.hpp>添加到头文件中
  • FMLocalNotificationPermission设为true
  • 表格上丢弃了TNotificationCenter组件

然后,我将以下代码放在按钮单击中:

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();
            }
    }
}

偶尔它会起作用......但很少也不会超过一次。大部分时间它根本没有(重复删除和重新安装应用程序)。

接下来,我尝试了他们提供的“立即显示通知消息”代码:

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();
      }
 }
}

这段代码根本没有任何事情发生。我已经从头开始尝试了几次,我确信我可以根据他们的例子对其进行编码。我正在使用10.3(Embarcadero®C++ Builder 10.3版本26.0.32429.4364)。我认为我的代码有问题,除了蓝月亮一次它有效。

我的目标是iPhone运行12.1.4,我尝试使用SDK11.4和SDK12.0构建,没有区别。当我第一次运行应用程序时,我得到“允许或不允许”弹出窗口,我的应用程序随后显示在通知设置中 - 只是不起作用。

拉斯

更新3-25-2019:如果我运行那个顶级代码块(从iPhone上点击按钮),它现在每次都会运行 - 但只有在我点击后立即杀死应用程序时才会运行。 10秒后它会触发通知。如果我让我的应用程序运行,为什么不会出现通知?

firemonkey c++builder
1个回答
0
投票

您确定在单击按钮时从Button调用“Present NotificationClick”吗?

© www.soinside.com 2019 - 2024. All rights reserved.