Reputation: 524
I know this question is asked multiple times. So bear with me here.
I am trying to implement Azure Notification Hub with My Android / iOS clients using Xamarin Forms.
For Android its going ok but for iOS I am not receiving any Notifications.
Here is a checklist of what I have done for iOS
But I am unable to receive any notification and also none of the functions are called(DidRegisterUserNotificationSettings,WillPresentNotification,ReceivedRemoteNotification,DidRegisterUserNotificationSettings,FailedToRegisterForRemoteNotifications,DidReceiveRemoteNotification)
But RegisteredForRemoteNotifications
is called
I also tested the devicetoken with or without removing the '<> '
from it but no success.
What may be the issue?
Here is my code
public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
{
GlobalVariables.Instance.PnsToken = deviceToken.Description
.Replace("<", string.Empty)
.Replace(">", string.Empty)
.Replace(" ", string.Empty)
.ToUpper();
RegisteredForHub(application, deviceToken);
}
public void RegisteredForHub(UIApplication application, NSData deviceToken)
{
string pnsHandle = deviceToken.Description
.Replace("<", string.Empty)
.Replace(">", string.Empty)
.Replace(" ", string.Empty)
.ToUpper();
_hub = new SBNotificationHub(Constant.ListenConnectionString, Constant.NotificationHubName);
_hub.UnregisterNative((error) =>
{
if (error != null)
{
Debug.WriteLine($"Unable to call unregister Native {error}");
}
});
_hub.UnregisterTemplate("defaultTemplate",(error) =>
{
if (error != null)
{
Debug.WriteLine($"Unable to call unregister Template {error}");
}
});
// update registration with Azure Notification Hub
_hub.UnregisterAll(deviceToken, (error) =>
{
if (error != null)
{
Debug.WriteLine($"Unable to call unregister {error}");
return;
}
var tags = new NSSet(Constant.SubscribeTags);
_hub.RegisterNative(pnsHandle, tags, (errorCallback) =>
{
if (errorCallback != null)
{
Debug.WriteLine($"RegisterNativeAsync error: {errorCallback}");
}
});
var templateExpiration = DateTime.Now.AddDays(120)
.ToString(System.Globalization.CultureInfo.CreateSpecificCulture("en-US"));
//_hub.RegisterTemplate(deviceToken, "defaultTemplate", Constant.ApnTemplateBody, templateExpiration,
// tags, (errorCallback) =>
// {
// if (errorCallback != null)
// {
// Debug.WriteLine($"RegisterTemplateAsync error: {errorCallback}");
// }
// });
});
Upvotes: 2
Views: 530
Reputation: 524
After alot of trials and errors and so many hours googling. I found out the issue was with the Azure.
I had uploaded the the correct certificate but the password was one character of due to which no notifications were sent.
Azure should prompt the user for APNs if the user has entered the wrong password for its Certificate file.
Upvotes: 0