'Update permission status after permission is allowed in delphi mobile app
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;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
