User Notifications

The UserNotifications framework (UserNotifications.framework) supports the delivery and handling of local and remote notifications. You use the classes of this framework to schedule the delivery of local notifications based on specific conditions such as time or location. Apps and extensions also use this framework to receive and potentially modify local and remote notifications when they are delivered to the user’s device.

Note: This framework replaces the previous platform-specific interfaces for creating and scheduling local and remote notifications. The platform-specific notification interfaces deprecated and their usage should be avoided.

Well, all this means that apple has deprecated LocalNotifications and it's time to get familiar with a new notifications framework.

Setup

The first step is just to enable User Notifications API under the plugin settings. See the screenshot below:

Authorization

Requesting authorization is required of all apps that support the delivery of notifications. You request authorization using the:

using SA.IOSNative.UserNotifications;
...
NotificationCenter.RequestPermissions ();

 

 

API Reference

NotificationCenter

namespace SA.IOSNative.UserNotifications {
	
	public class NotificationCenter  {
		
		/// <summary>
		/// Schedules a local notification for delivery.
		/// <param name="request"> The notification request to schedule.This parameter must not be null. </param> 
		/// <param name="callback"> The callback to fired with the results. </param> 
		/// </summary>

		public static void AddNotificationRequest(NotificationRequest request, Action<SA.Common.Models.Result> callback);
	}
}

NotificationContent

namespace SA.IOSNative.UserNotifications {

	public class NotificationContent  {

		/// <summary>
		/// A short description of the reason for the alert.
		/// </summary>
		public string Title {get; set;}

		/// <summary>
		/// A secondary description of the reason for the alert.
		/// </summary>
		public string Subtitle {get; set;}

		/// <summary>
		/// The message displayed in the notification alert.
		/// </summary>
		public string Body {get; set;}


		/// <summary>
		/// The number to apply to the app’s icon.
		/// </summary>
		public int Badge {get; set;}

		/// <summary>
		/// The name of the launch image to display when your app is launched in response to the notification
		/// </summary>
		public string LaunchImageName {get; set;}


		/// <summary>
		/// A dictionary of custom information associated with the notification.
		/// </summary>
		public Dictionary<string, object> UserInfo  {get; set;}
	}
}

NotificationRequest

namespace SA.IOSNative.UserNotifications {

	public class NotificationRequest  {

		/// <summary>
		/// Initializes a new instance of the <see cref="NotificationRequest{T}"/> class.
		/// <param name="id"> The unique identifier for this notification request. </param>
		/// <param name="content"> The content associated with the notification. </param>
		/// <param name="trigger"> The conditions that trigger the delivery of the notification. </param>
		/// </summary>
		public NotificationRequest(string id, NotificationContent content, NotificationTrigger trigger);

		/// <summary>
		/// The unique identifier for this notification request.
		/// </summary>
		public string Id {get;}
			
		/// <summary>
		/// The content associated with the notification.
		/// </summary>
		public NotificationContent Content {get;}

		/// <summary>
		/// The conditions that trigger the delivery of the notification.
		/// </summary>
		public NotificationTrigger Trigger {get;}
	}
}

NotificationTrigger

namespace SA.IOSNative.UserNotifications {

	public abstract class NotificationTrigger  {

		public void SetRepeat(bool repeats);
	}
}

CalendarTrigger

namespace SA.IOSNative.UserNotifications {

	public class DateComponents {

		public int? Year;
		public int? Month;
		public int? Day;
		public int? Hour;
		public int? Minute;
		public int? Second;
		public int? Weekday;
		public int? Quarter;
	}

	public class CalendarTrigger : NotificationTrigger {

		public CalendarTrigger(DateTime date);
		public CalendarTrigger(DateComponents dateComponents);

	}
}

TimeIntervalTrigger

namespace SA.IOSNative.UserNotifications {

	public class TimeIntervalTrigger : NotificationTrigger {

		public TimeIntervalTrigger(int secondsInterval);
	}
}

AlertStyle

namespace SA.IOSNative.UserNotifications {

	public enum AlertStyle  {
		None = 0,
		Banner,
		Alert
	}
}

AuthorizationStatus

namespace SA.IOSNative.UserNotifications {

	public enum AuthorizationStatus  {

		// The user has not yet made a choice regarding whether the application may post user notifications.
		NotDetermined = 0,

		// The application is not authorized to post user notifications.
		Denied,

		// The application is authorized to post user notifications.
		Authorized
	}
}

NotificationStatus

namespace SA.IOSNative.UserNotifications {
	
	public enum NotificationStatus  {

		// The application does not support this notification type
		NotSupported  = 0,

		// The notification setting is turned off.
		Disabled,

		// The notification setting is turned on.
		Enabled
	}
}