-
Notifications
You must be signed in to change notification settings - Fork 68
Location Notifications
From Version 10.0.1 and above
You can set up Geofence to trigger a notification.
In iOS, make sure to specify LocationAuthorization type
if (await LocalNotificationCenter.Current.AreNotificationsEnabled() == false)
{
await LocalNotificationCenter.Current.RequestNotificationPermission(new NotificationPermission
{
IOS =
{
LocationAuthorization = iOSLocationAuthorization.WhenInUse
}
});
}
By default, notification triggered on Entry.
var notification = new NotificationRequest
{
NotificationId = notificationId,
Title = "Test",
Description = $"Test Description",
Geofence =
{
Center =
{
Latitude = -37.003578276665095,
Longitude = 174.78484574983338
},
RadiusInMeters = 100
}
};
LocalNotificationCenter.Current.Show(notification);
var notification = new NotificationRequest
{
NotificationId = notificationId,
Title = "Test",
Description = $"Test Description",
Geofence =
{
Center =
{
Latitude = -37.003578276665095,
Longitude = 174.78484574983338
},
RadiusInMeters = 100,
NotifyOn = NotificationRequestGeofence.GeofenceNotifyOn.OnEntry | NotificationRequestGeofence.GeofenceNotifyOn.OnExit
}
};
LocalNotificationCenter.Current.Show(notification);
var notification = new NotificationRequest
{
NotificationId = notificationId,
Title = "Test",
Description = $"Test Description",
Geofence =
{
Center =
{
Latitude = -37.003578276665095,
Longitude = 174.78484574983338
},
RadiusInMeters = 100,
iOS =
{
Repeats = true
},
Android =
{
ExpirationDurationInMilliseconds = -1
},
}
};
LocalNotificationCenter.Current.Show(notification);
Follow platform-specific setup from
https://learn.microsoft.com/en-us/dotnet/maui/platform-integration/device/geolocation?view=net-maui-7.0&tabs=android https://learn.microsoft.com/en-us/dotnet/maui/platform-integration/device/geolocation?view=net-maui-7.0&tabs=ios
https://developer.apple.com/documentation/corelocation/requesting_authorization_for_location_services https://developer.apple.com/documentation/bundleresources/privacy_manifest_files/describing_data_use_in_privacy_manifests
Important You must add the required keys to your app’s Info.plist file. If a needed key isn’t present, authorization requests fail immediately. You must add NSPrivacyCollectedDataTypePreciseLocation or NSPrivacyCollectedDataTypeCoarseLocation to your PrivacyInfo.xcprivacy file