firemonkey - iOS 通知零星 (FMX)
问题描述
按照此链接上的 Embarcadero 文档,我正在 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 进行构建,没有区别。当我第一次运行应用程序时,我得到“允许或不允许”弹出窗口,我的应用程序随后显示在通知设置中 - 只是不起作用。
拉斯
2019 年 3 月 25 日更新:如果我运行最上面的代码块(从 iPhone 上的按钮单击),它现在每次都会运行 - 但只有当我在单击后立即终止应用程序时。10 秒后,它会触发通知。如果我让我的应用程序运行,为什么不会出现通知?
解决方案
您确定单击 TButton 时是从 TButton 调用“PresentNotificationClick”吗?
推荐阅读
- ansible - 使用 Ansible 创建接口配置文件
- r - 如何在 R 中修复此错误 - FUN(X[[i]], ...) 中的错误:找不到对象“Id”
- c - 这个双指针取消引用在这里是如何工作的
- python - 如何引用模块中的数据资产?
- azure-devops - Azure DevOps - 禁用和启用存储库
- python - 使用我创建的代码进行操作时,该值从第二个值输出为“X-1”
- python - 如何使用 to_sql 将数据框存储在 sql server 数据库中?
- c# - C# 将动态 JSON JToken 解析为列表
- jointjs - 为什么路径不随矩形缩放?
- swift - 带视频的 SCNPlane 在模拟器上播放,但在设备上不播放