首页 > 解决方案 > iOS 通知零星 (FMX)

问题描述

按照此链接上的 Embarcadero 文档,我正在 iOS 上测试通知(在使用 C++ 构建的 FMX 应用程序中)。我已经完成了以下操作:

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

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)。我认为我的代码有问题,除非在蓝月亮中它可以工作。

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

拉斯

2019 年 3 月 25 日更新:如果我运行最上面的代码块(从 iPhone 上的按钮单击),它现在每次都会运行 - 但只有当我在单击后立即终止应用程序时。10 秒后,它会触发通知。如果我让我的应用程序运行,为什么不会出现通知?

标签: firemonkeyc++builder

解决方案


您确定单击 TButton 时是从 TButton 调用“PresentNotificationClick”吗?


推荐阅读