We are trying to use the NotificationHubClient in Microsoft.ServiceBus.Notifications. We are having a strange problem which the code below shows where we register the Device like so:
NotificationHubClient client = GetHubclient();
var task = client.CreateMpnsNativeRegistrationAsync(deviceToken, tags);
Task.WaitAll(task);
This registers the device fine and if we send a test toast message from the azure portal debug page it comes through to the windows phone without issue. However if we call the following:
var sentTask = client.SendMpnsNativeNotificationAsync(GetPayload());
Task.WaitAll(sentTask);
private static string GetPayload()
{
return "<wp:Notification xmlns:wp=\"WPNotification\"><wp:Toast><wp:Text1>Great News</wp:Text1><wp:Text2>Great News</wp:Text2></wp:Toast></wp:Notification>";
}
No toast notification arrives on the phone and if we then go and try to send a test toast notification again from the debug page of the azure portal it no longer works and the following error is displayed:
The Push Notification System handle for the registration is invalid
None of this is making sense, we have enabled testSend and there are no errors coming back from the client in the code, in fact it says everything was successful the first time even though this appears to break the PNS handle.
Has anyone come across this before?
It turns out that if the Xml declarations are missing:
<?xml version="1.0" encoding="utf-8"?>
Then you can no longer send push notifications to any phones you tried to send a push notification to as it is invalidated. This seems pretty awful, sure don't send the notification if the payload is invalid but why invalidate the PNS.
Related
We've been trying to get iOS push notifications to work but it's been very inconsistent. We've created a test project with as little code as possible just to get notifications to work.
We decided to test with alert notifications since we couldn't even get that to work consistently.
This is what we've been doing in the FinishedLaunching method of the AppDelegate:
UNUserNotificationCenter.Current.Delegate = this;
var authOptions = UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound;
UNUserNotificationCenter.Current.RequestAuthorization(authOptions, (granted, error) =>
{
LogInformation("RequestAuthorization", $"Granted: {granted}, Error: {error}");
if (granted)
InvokeOnMainThread(UIApplication.SharedApplication.RegisterForRemoteNotifications);
});
And we log the registration token of the device in the console so that we can use that to send notifications.
public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
{
LogInformation("RegisteredForRemoteNotifications", "init");
var token = ExtractToken(deviceToken);
LogInformation("RegisteredForRemoteNotifications", token);
}
That's basically all we have in the app for now.
We use the notification token in a test app to send notifications to that specific device.
These are our results:
Use case 1
Restart device
Send notification to device
Result: Notification shows up and all new notifications keep working too.
Use case 2
Restart device
Send notification to device
Result: Notification is not shown and no matter how often you send the notification, it won't be shown.
Use case 3
Restart device
Send notification to device
Notification is not shown.
Restart device
Result: Notification shows up and all new notifications keep working too.
Use case 4
Restart device
Start application once
Put app in background, or close it completely
Send notification to device
Result: Notification is shown and all new notifications keep working too.
So it looks like that once we receive 1 notification, all future notifications will work too up until the device is restarted.
After restarting the device, it's basically a coinflip: You either are lucky and receive a notification and all future notifications. Or you don't receive anything at all.
We want to receive notifications consistently and are trying to figure out how to get this done and we hope someone can shed some light into this matter.
Thanks in advance.
Notes
We're using a 6th gen iPad with iOS 13.5.1
iPad is WiFi only
We've got a stable WiFi and internet connection
It seems that we programmed everything correctly because when we use a test app that we made everything works fine. But now that were trying to create the real app it doesn't work. When we try to send a push message from Notification Hubs we get the message "message was successfully sent but there were no matching targets". We tripple checked all the necessary fields and everything is the same. Somehow the message is not being delivered and we can't find the reason why.
I am working with Cisco phones and i want to send them alert messages.
I do this by posting the following to the phone
"<CiscoIPPhoneExecute><ExecuteItem URL=\"Play:chime.raw\"/><ExecuteItem Priority=\"0\" URL=MY GET MESSAGE URL></CiscoIPPhoneExecute>";
My HTTP server then responds with a CiscoIPPhoneText xml object.
This is all working fine, however it is my desire not to have the messages stacking up on top of each other so that the user does not have to dismiss each message individually. I wish only for the most recent message to remain active on the phone so regardless of how many messages the phone has received the user can dismiss one and be returned home.
At first i included an init:services uri in the post but this caused a conflict with another service and my CiscoIPPhoneText was being dismissed immediately by the other service (i have no control over the other service).
Is there a way to return the phone to the home screen before an CiscoIPPhoneText is displayed or any other way to ensure that only one message is active?
Thanks
I found the answer
App:Close:0 is an internal URI which closes the current (or specified) application.
All my messages have the same AppId so when this URI is invoked all my messages close
I'm working on a project which receive notification from GCM server.
I've got the registration ID from GCM server and i send it to my server application which save it in the database.
My device receive the message but when I try to send another one, the precedent is replaced.
I know that we've 2 types of message:
Collapsible "send to sync"
Non-Collapsible
So without changing the name of the message, how can I get two message send at different time?
UPDATE 1:
When my device is offline (for example airport mode activated), I try
to send for example 2 messages from my application server to Google
server (I read that Google stores all the messages). But when I
desactivate this mode, I receive only the last message sent.
I use different collapse_key for different message and I receive all
of them (of course when the device online).
Is anybody knows how can I fix this?
The collapse key is relevant only to messages that were sent to the GCM server but haven't reached the destination device yet (if more than one such message has the same collapse key, only one of them will be sent to the device when it becomes online).
In your question you describe a different situation - the first message is received by the device and then the second message is received by the device and replaces the original message. That has nothing to do with GCM. It has to do with the way your application handles the received messages. For example, if your application code that receives the message displays is as a notification, it's up to you to decide whether a new message will override the existing notification or create a new notification.
You need to make sure that the value of the 'collapse_key' field in each message is different
I'm trying to send a push notification using https://github.com/Redth/PushSharp
I'm using the sample project as is (having commented out the non ios stuff from program.cs), I confirmed that the app i'm using is the correct app, I've regenerated the developer push cert.
I'm running the app from xcode, so that it is devlopment providsioned..
The message seems to go fine, but then comes back
Waiting for Queue to Finish...
Sent: Apple -> {"aps":{"alert":"1 Alert Text!","badge":7,"sound":"default"}}
Queue Finished, press return to exit...
Device Subscription Expired: Apple -> [Device Id Removed]
I'm getting the device id from my app, to confirm it coumes out broken into Hex Octets, and i simply remove the spaces
So... not sure where to go from here, seems that apns is saying the app doesn't exist on my device, but it certainly does..
This is almost always due to a mismatch between the development and production provisioning profile certificates.
Check you're using the correct one... if this is still a problem!