You do not have to add any interfaces to your platform projects, Just intall nuget package to both projects Android/IOS.
on IOS you should add:
// Ask the user for permission to get notifications on iOS 8.0+
if (UIDevice.CurrentDevice.CheckSystemVersion (8, 0)) {
var settings = UIUserNotificationSettings.GetSettingsForTypes (
UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound,
new NSSet ());
UIApplication.SharedApplication.RegisterUserNotificationSettings (settings);
}
to your method:
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
in AppDelegate:
Then in your shared project you call:
using Plugin.LocalNotifications.Abstractions;
CrossLocalNotifications.Current.Show("You've got mail", "You have 793 unread messages!");
As of replacing your current page, you do not have to do anything, Xamarin Forms will handle that for you.
Also on android, you can controll, you application relaunch behavior by setting LaunchMode of your MainActivity:
Example:
LaunchMode = Android.Content.PM.LaunchMode.SingleInstance, AlwaysRetainTaskState = true
To read more about LauchModes on Android, please read:
https://developer.android.com/guide/components/tasks-and-back-stack.html
And check additionl activity flags:
FLAG_ACTIVITY_NEW_TASK
FLAG_ACTIVITY_CLEAR_TOP
FLAG_ACTIVITY_SINGLE_TOP
Currently this plugin does not allow to catch any notification inside app.
But you can do this, by using platform specific functionality
IOS:
Please refer to
https://developer.xamarin.com/guides/cross-platform/application_fundamentals/notifications/ios/remote_notifications_in_ios/
public override void ReceivedLocalNotification(UIApplication application, UILocalNotification notification)
{
MessagingCenter.Send<MainPage> (this, "IOS notification received");
}
Android:
After reading through source of this plugin, i've discovered, that youcan check Bundle in your on create method for key ScheduledAlarmHandler.LocalNotificationKey
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
if(bundle.ContainsKey(ScheduledAlarmHandler.LocalNotificationKey)){
//App launched form notification
MessagingCenter.Send<MainPage> (this, "Android notification received");
}
}
Also you can try to use BroadcastReceiver class;
https://developer.xamarin.com/api/type/Android.Content.BroadcastReceiver/