requestPermission method
Request permission from the user to show them notifications. This is required to show user notifications. Otherwise, notifications may silently get received by the application.
This always returns true on Android, since you don't need permissions to show notifications to the user.
You can customize the request by specifying whether the app should
display alert
s, play sound
s, update the app's badge
, display
notifications in the carPlay
environment, whether the app should ignore
the mute switch and Do Not Disturb by setting criticalAlert
, and set
whether the system should display a button for in-app notification
settings (iOS 12+) with providesAppNotificationSettings
.
With provisional
you can configure whether the app should send
notifications on a trial basis, by delaying the permission request until
the user first sees the first notification. iOS 12+. In that case a
notification is first delivered quietly, and the user gets an option
to deliver it more prominently. If provisional
is true, the permission
request alert will not be shown to the user, regardless of other options
passed in. For more information, see
Use Provisional Authorization to Send Trial Notifications
You can also choose if Siri should have an ability to automatically read
out messages over AirPods (matters on iOS 13+. Deprecated in iOS 15+,
because it is automatically/always granted).
Asynchrously returns a bool indicating whether the permission was granted
Implementation
Future<bool> requestPermission({
bool alert = true,
bool announcement = true,
bool badge = true,
bool carPlay = true,
bool criticalAlert = false,
bool providesAppNotificationSettings = false,
bool provisional = false,
bool sound = true,
}) async {
if (io.Platform.isIOS) {
return invokeRequest<bool>(PlatformMethod.pushRequestPermission, {
TxPushRequestPermission.alert: alert,
TxPushRequestPermission.announcement: announcement,
TxPushRequestPermission.badge: badge,
TxPushRequestPermission.carPlay: carPlay,
TxPushRequestPermission.criticalAlert: criticalAlert,
TxPushRequestPermission.providesAppNotificationSettings:
providesAppNotificationSettings,
TxPushRequestPermission.provisional: provisional,
TxPushRequestPermission.sound: sound,
});
} else {
return true;
}
}