We are developing a cross-platform application (Android and iOS) using Xamarin.Forms. So far, we've managed to get the app to work just fine, so cool!
We have added several push notifications to our application using the Azure Notification Hub, GCM (for android) and APNS (for iOS). And it works almost perfectly!
In fact, we have the last problem: everything is fine for Android, and we can register for push notifications using iOS, but we cannot add some tags to our registrations.
Indeed, we should be able to send push notifications to one user or one group of users, and not to all. To do this, we do this in our web api method:
if (user.DeviceType.Equals("Android"))
{
registration = new GcmRegistrationDescription(handles.Handle);
}
else
{
registration = new AppleRegistrationDescription(handles.Handle);
}
registration.Tags = new HashSet<string>();
registration.Tags.Add("usermail:" + user.Email);
registration.Tags.Add("userid:" + user.Id);
registration.Tags.Add("userdevice:" + user.DeviceType);
registration.Tags.Add("usertype:" + tag);
registration.RegistrationId = handles.RegistrationId;
await NotificationHelper.Hub.CreateOrUpdateRegistrationAsync(registration);
Handle Android:
protected override void OnRegistered(Context context, string registrationId)
{
[...]
}
iOS:
public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
{
[...]
var DeviceToken = deviceToken.Description;
if (!string.IsNullOrWhiteSpace(DeviceToken))
{
DeviceToken = DeviceToken.Trim('<').Trim('>');
}
UserInformations.Handles.RegistrationId = DeviceToken.Replace(" ", "").ToUpper();
[...]
}
Android ( ), iOS.
NotificationHelper.Hub.CreateOrUpdateRegistrationAsync();
, , registrationId . , iOS, , , , , - .
, , , iOS APNS?
!
EDIT: , . , , . 2 , :

, , , DeviceToken, , RegistrationId, ... , :/