iOS通知零星(FMX)

时间:2019-02-26 22:39:43

标签: firemonkey c++builder

在使用Embarcadero文档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)。我认为我的代码有问题,除非在蓝色月亮中能正常工作。

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

鲁斯

更新3/25/2019 :如果我运行该代码的最高代码块(通过单击iPhone上的按钮),则该代码每次都将运行-但前提是我单击后立即杀死该应用程序。 10秒后,它会触发通知。如果我让我的应用程序运行,为什么通知不会出现?

1 个答案:

答案 0 :(得分:0)

确定要在单击TButton时调用“ PresentNotificationClick”吗?