Unclear error message on sending a notification to iOS - apple-push-notifications

I'm trying to send a notification via C# SDK. I'm sending notifications for iOS.
string payload = "{\"aps\" : { \"alert\" : \"Message received from Bob\" }}";
var outcome = hub.SendAppleNativeNotificationAsync(payload, new[] { "b6a5d9c3-4297-422f-9a8d-b7979c30a5f8" }).GetAwaiter().GetResult();
Registration works fine, I can retrieve registered users, but I receive errors on sending. The error message is
Contract mismatch between ServiceBus and the Push Notification System
I've looked into manage.windowsazure.com for monitoring and saw that there were errors of type “Bad channel error”.
I assume that I should try to change my region for NH and probably the problem will go away, but is there anything else I could look at to resolve this issue?
Forgot to mention that everything was working on the first day I started to work with push notifications and only after several days became broken without any changes.

you may have open port 2135 and also add APN certificate

I didn't figured out what does that error mean but at least found the root cause. It was Testflight that by some obscure reasons uses production gateways to send notifications and not sandbox, and my NH has been configured with sandbox certificate, that's why it didn't work.

Related

Sending and receiving own message

Hi everyone.
I have right now a simple multiplayer game but it is out of sync.
If I could receive my own message from the RealTimeMessageReceivedListener that would be awesome but I can't.
How I am sending my info:
for(Participant p : participants){
Games.RealTimeMultiplayer.sendUnreliableMessage(_gameHelper.getApiClient(),message.getBytes(),roomId,p.getParticipantId());
}
As you can see I'm sending my messages to everyone (even to myself). However at the RealTimeMessageReceivedListener I don't receive any information about my own message.
can you help me with this?
The API does not allow this according to:
the Real-time Multiplayer documentation. See section on Sending Messages. Also, the "sender participant" needs to be excluded if you intend to switch to sending broadcast messages with the API instead;
rationale provided in issue submitted to the Google Play Plugin for Unity project on GitHub.

React To PushNotification Received even if the App is Closed

I know there are a lot of questions related to this subject, but after searching I found out that they all say that if the app is closed then the only way is to fetch the notification again from the server once the app is opened or if the app is opened from the notification then you can handle it in didFinishWithLaunch but using WhatsApp, this is not the case...
I tried sending a message to phone B (which had whatsapp closed), Phone B received the notification. Then I turned off the internet on Phone B and opened the app and still received the chat message.
Can anyone guide me on how to do this?
Probably you should use one of background modes - "remote-notification".
After enabling it, you can send push with payload like
{
"alert": "",
"badge": "0",
"content-available": 1,
"sound": ""
}
if you specify content-available key equal 1, iOS will wake your app and call application:didReceiveRemoteNotification:fetchCompletionHandler: in app delegate and you have some time to proceed push and prepare app (like download this new message to device). Here is Apple docs link with info about push payloads.
However please be aware that this push delivering is not guaranteed. Apple tells
(Newsstand apps are guaranteed to be able to receive at least one push with this key per 24-hour window.)
In our experience you likely receive it most of the time, but not always. For example app delegate callback will not be called if user swiped to close your app.
Also you need to finish execution in 30 seconds or less and call the block in handler parameter (you can check discussion section of method documentation for more details)

Debugging Google cloud messaging push messages

I am trying to send push messages to an android application.
The POST https://android.googleapis.com/gcm/send
seems to succeed and I get something (with some numbers changed) like:
{"multicast_id":9999063399994069899,
"success":1,
"failure":0,
"canonical_ids":0,
"results":[{"message_id":"0:1416520599679103%8d7d198de508343a"}]}
but I don't seem to get the notification on the device...
Is there anything that can be done with the message_id it track it forward ?
Can I somehow tell me if Google actually tired to deliver it to the device and what was the result of the attempt?
I know it's an old question and you might have solved it yourself by now, but for completeness I would like to post a solution here.
By now you can find the option GCM Diagnostics in your Google Play Developer Console when you have your app selected. It's placed on the left hand side.
You just post a registration token or a message id and will shortly see a summary of push notifications connected to this token/id, plus additional debug information.
Cheers!
well, at least until someone would provide a better answer about debugging based on message ids.
It turns out the problem in my case was that the phone gap plugin in I was using was expecting a "message" field in the push notification message payload.
A bug on my server side made this message not to exist so it was not displayed in the phones notification area...
my thanks to #Eran for partially pushing my towards the right line of thought.

Azure Notification Hub Register iOS Device Always Returns Unauthorized

Early on in developing an iOS app with Xamarin, another developer and I got push notifications working for it using the Azure Messaging Component. It's a few months later now, and sometime between then and now, the push notifications stopped working. The code is still basically the same as before (which is nearly identical to the example code for the component), it was just moved to its own class for maintainability.
On Hub.UnregisterAllAsync(DeviceToken, error =>, error is:
The operation couldn’t be completed. (NSURLErrorDomain error -1012.)
On Hub.RegisterNativeAsync(DeviceToken, tags, error =>, error is:
URLRequest failed for <NSMutableURLRequest: 0x167dbd80>
{ URL: https://[our namespace].servicebus.windows.net/[our hub name]/Registrations/?$filter=deviceToken+eq+'[long token]'&api-version=2013-04 }
with status code: unauthorized
We tried a new hub, and a new namespace with a new hub, but without luck. I've rolled back the changes we've made since it was working, but with no luck there either. The same error happens on multiple devices, on multiple networks. It never shows any errors in the portal for APNS, so I'm assuming this is something with authenticating to the Hub itself. What is really weird is that a Windows Store app that we wrote to test this registers and receives notifications using the same credentials without any issue. Can anyone point me in the right direction on this? The error messages above aren't very helpful.
It turns out that the test devices all had the automatic date and time synchronization turned off. The iPad I was primarily testing with was only off by about 20 or 30 seconds, so I didn't notice it was off. Another question involving the same thing with a Windows or Windows Phone registration clued me into it, but I can't find the link to it now. Apologies for that, thanks to whoever that was!
Looking at the API, it makes sense why it's so sensitive to this. It uses the date and time to generate the SAS Token, thus the unauthorized response when the time is just a few seconds off.

how to register for a new channel uri with the MPNS?

How do i get a new channel uri from MPNS ? Its returning the same one from the last few calls.And if I use it , it returns 404 error.So I want to get a new channelUri to test the push notification.
Any help ?
AFAIK, you only can register ONE push channel for Application, and registered URL remains the same until MS decide to change it.
However, system seems a little buggy. For example, you use
var pushChannel = HttpNotificationChannel.Find(K_PushChannelName);
to obtain your channel, sometimes it returns null, but when trying to create a new one with a call to Open() you get an exception or gets an empty URI.
This can happen by a lot of reasons. You have used all 500 push notifications/day without certificate, you have another push channel open in the app, or it is a simply Microsoft server fail.
One workaround for some errors is to delete application from phone/emulator and re-install it.
I've experienced a lot of problems with push channels, until have to wait 24/48 hours to continue developing. However, when in production all seems being working ok. It seems happens only when you do a lot of calls to channel search/open.

Resources