-
Notifications
You must be signed in to change notification settings - Fork 68
Location Notifications
Elvin (Tharindu) Thudugala edited this page Jan 15, 2023
·
7 revisions
From Version 10.0.1 and above
You can set up Geofence to trigger a notification.
By default notification trigged 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,
GeofenceNotifyOn = 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);
Important You must add the required keys to your app’s Info.plist file. If a required key isn’t present, authorization requests fail immediately.
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
...
.UseLocalNotification(config =>
{
config.SetPermission(new NotificationPermission
{
IOS =
{
LocationAuthorization = iOSLocationAuthorization.WhenInUse
}
})
});
return builder.Build();
}
}
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
LocalNotificationCenter.RequestLocationPermission(iOSLocationAuthorization.WhenInUse);
LoadApplication(new App());
return base.FinishedLaunching(app, options);
}
}