iOS通知零星(FMX) [英] iOS notifications sporadic (FMX)

查看:68
本文介绍了iOS通知零星(FMX)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Embarcadero文档之后在此链接 i在iOS上测试通知(在使用C ++构建的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:


  • 添加了 #include< System.Notification.hpp> 到头文件

  • FMLocalNotificationPermission 设置为 true

  • TNotificationCenter 组件拖放到表单上

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

没有任何反应码。我已经从头开始尝试了好几次,并且可以肯定的是,我正在按照他们的示例进行编码。我正在使用10.3(Embarcadero®C ++ Builder 10.3版本26.0.32429.4364)。我认为我的代码有问题,但只有在蓝色月亮下才能起作用。

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.

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

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

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

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

推荐答案

您确定要从以下位置调用 PresentNotificationClick吗?单击TButton时会出现什么?

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

这篇关于iOS通知零星(FMX)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆