saturdaymp/XPlugins.Notifications

Generate Unique Identifier for Notifications

Closed this issue · 2 comments

When a notification is created it needs to be assigned a unique identifier. Currently it always returns zero. I think the unique identifier will be GUID unless I can think of something better.

Currently the Create method returns a integer. This will need to be updated so the Create signature looks like:

GUID Create([NotNull] string title, [NotNull] string message, [NotNull] Dictionary<string, object> extraInfo);

This will be a breaking change but it's only me using this plugin so no big deal. Plus it's still in alpha if someone else is using it. If you are that someone else using this plugin then thank you. I hope you find it useful.

For Android the notification number will be stored as "guid" in the intents extra info:

var notificationGuid = Guid.NewGuid();
var alarmIntent = new Intent(Application.Context, typeof(NotificationAlarmHandler));
alarmIntent.PutExtra("guid", notificationGuid);

// Other code.

return notificationGuid;

Similar for iOS:

var notificationGuid = Guid.NewGuid();
extraInfo.Add("guid", notificationGuid);

var notification = new UILocalNotification
        {
            AlertTitle = title,
            AlertBody = message,
            FireDate = NSDate.Now,
            UserInfo = NSDictionary.FromObjectsAndKeys(extraInfo.Values.ToArray(), extraInfo.Keys.Cast<object>().ToArray())
        };

// Other code.

return notificationGuid;

I've updated the create methods to return the GUID. To make sure it was working I also updated the Example Client to show the GUID for scheduled messages. Still need a big more work on the Example Client before closing this issue.

The create method has been updated to include a GUID. Also updated the example client to show the original notification and the values of the one received. Finally I added the last create method that takes a scheduled date as well as the extra info.

Currently the extra info only works for iOS and not Android. Also receiving notifications only works in iOS and not Android.