delphi移动应用程序允许权限后更新权限状态
我正在 Android 和 iOS 平台上开发一个 Delphi 移动应用程序,需要显示通知。当我第一次单击该按钮时,它将请求通知权限。但是,当我单击提示权限的对话框上的“允许”按钮后,通知不显示。我需要再次按下按钮才能显示通知。
有没有办法让我的应用程序在我允许应用程序的通知权限后立即获得状态?
下面是我的原型代码:
procedure TForm1.Button3Click(Sender: TObject);
begin
var notiCenter := TNotificationCenter.Create(nil);
notiCenter.OnPermissionRequestResult := NotificationCenterPermissionRequestResult;
if notiCenter.AuthorizationStatus <> TAuthorizationStatus.Authorized then
notiCenter.RequestPermission;
if FIsNotificationAllowed then begin
var noti := notiCenter.CreateNotification;
try
noti.Name := 'Button Click';
noti.Title := 'Button Click';
noti.AlertBody := 'Button Click';
notiCenter.PresentNotification(noti);
finally
noti.DisposeOf;
end;
end;
end;
procedure TForm1.NotificationCenterPermissionRequestResult(Sender: TObject;
const AIsGranted: Boolean);
begin
if AIsGranted then FIsNotificationAllowed := true
else FIsNotificationAllowed := false;
end;
I am developing a Delphi mobile app on both Android and iOS platforms that requires to show notifications. When I first click on the button, it will request notification permission. However, after I click on the 'Allow' button on the dialog that prompts for permission, the notification doesn't show. I need to press the button again in order to show the notification.
Is there any way to let my application get the status immediately after I allow notification permission for the application?
Below is my prototype code:
procedure TForm1.Button3Click(Sender: TObject);
begin
var notiCenter := TNotificationCenter.Create(nil);
notiCenter.OnPermissionRequestResult := NotificationCenterPermissionRequestResult;
if notiCenter.AuthorizationStatus <> TAuthorizationStatus.Authorized then
notiCenter.RequestPermission;
if FIsNotificationAllowed then begin
var noti := notiCenter.CreateNotification;
try
noti.Name := 'Button Click';
noti.Title := 'Button Click';
noti.AlertBody := 'Button Click';
notiCenter.PresentNotification(noti);
finally
noti.DisposeOf;
end;
end;
end;
procedure TForm1.NotificationCenterPermissionRequestResult(Sender: TObject;
const AIsGranted: Boolean);
begin
if AIsGranted then FIsNotificationAllowed := true
else FIsNotificationAllowed := false;
end;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论