I am implementing Azure Notification hub into an cross platform Xamarin App. The way I am uniquely identifying each device that registers for notifications is by temporarily storing the RegistrationId that azure assigns to the phone. Once the user has logged in am I sending the RegstrationId and some of the user's unique characteristics to a back-end service. The RegistrationId is being used to identify the phone and then the user's detail are being added to that phone as tags for tagged notifications.
This works on Android as all I have to do to obtain the registrationId is the following:
var regID = hub.Register(token, tags.ToArray()).RegistrationId;
However the equivalent for iOS does not work as the class SBNotificationHub does not include any methods to get the RegistrationId. How do I obtain this Azure RegistrationId for iOS devices?
Thanks.
I believe you can get a device id in the RegisteredForRemoteNotifications
override in AppDelegate
class as noted in this documentation.
Try adding the following to your AppDelegate
class:
// Add to top of class file, outside of namespace
using Newtonsoft.Json.Linq;
// Add inside of class
public override void RegisteredForRemoteNotifications(UIApplication application,
NSData deviceToken)
{
const string templateBodyAPNS = "{\"aps\":{\"alert\":\"$(messageParam)\"}}";
JObject templates = new JObject();
templates["genericMessage"] = new JObject
{
{"body", templateBodyAPNS}
};
// Register for push with your mobile app
Push push = TodoItemManager.DefaultManager.CurrentClient.GetPush();
push.RegisterAsync(deviceToken, templates);
}
I would think that the deviceToken is what you are looking for in iOS?