Push notification from local API in xamarin forms - xamarin

I am having an API locally hosted in one of the servers (LAN). What I am looking to understand if it is feasible to enable push notification from the server in case of a record entry. Every time a post request is made to the local server, Is it possible to push a notification to a certain mobile device? Please note, I am not considering push notification from web services such as google, Azure, Firebase etc.

It is feasible.
As Sushi said, you can use WebSockets or other Sockets to keep connect between Apps and Server. When client connected to your server, server will record which app is connecting.
By the way, you can custom notification's url between server and app.Use some special characters to distinguish between your various parameters, such as &/[ ]. You are free to set the header and body style of the message. Also, when your message needs to be encrypted, some encryption methods can be used.
Here is a similar discussion about Building an Android notification server can be refer .

Related

Interact with slack bot without a public accessible server

For some security reasons that I can't have a public accessible server to receive data from slack.
So, this is what I'm planning to do:
Inbound message from slack: using RTM API
Outbound message to slack: using RTM API or Web API
Questions:
Any better alternatives?
Any restrictions? (AFAIK, buttons and drop downs can't work)
If Web API reach rate limit, can I use incoming webhook as a backup plan?
RTM only approach
Yes, that would work. With only the RTM API you are limited to:
receiving and responding to messages
Other RTM events.
You can't use any interactive functionality like:
Interactive components (buttons, menus, datepickers)
Dialogs
Rate limit on message posting
Using the webhook as "backup" to circumvent the rate limit is not an option, since the rate limit of posting max 1 message per second applies to all form of message posting.
From the documentation:
In general, apps may post no more than one message per second per
channel, whether a message is posted via chat.postMessage, an incoming
webhook, or one of the many other ways to send messages in to Slack.
Alternatives
You did not give any details about the reasons why your app can't expose an endpoint to the public Internet. But you might want to consider using a VPN tunnel like ngrok.
Yes! Socket Mode
There is a new alternative from slack, Socket Mode, which doesn't require a publicly accessible server.
Note: this is only for private apps.
With Socket Mode you have an API token and your server uses it to communicate with Slack's servers and create a two way socket connection. This means your Slack Bot's code can run on a machine behind a firewall and not require any inbound ports to be opened.
Slack message delivery requires an acknowledgement once you get the message, or else they may retry to deliver it.
Limitations
Socket Mode has two main limitations:
Apps using Socket Mode are not currently allowed in the public Slack App Directory.
Socket Mode is only available for apps using new, granular permissions. If you created your app on or after December of 2019, good news: your app already uses the new permissions. Otherwise, you may have to migrate your classic Slack app to use granular permissions before turning on Socket Mode.

Using SignalR to push to clients from a long running process

Firstly, here is state of my application:
I have a request coming in from a client (angularjs app) into my API (web api 2). This request is processed and a record is stored in a database. A response is then sent back to the client.
Currently, I have a windows service polling and processing this record(s).
Processing this record can be long running. As a side effect to processing this record, there might be notifications generated to be sent back to one or more clients.
My question is how do I architect this, such that I can utilise SignalR to be able to push the notifications back to the client.
My stumbling block:
I can register and store (in-memory backed by a db) the client's SignalR connectionid along with the application's own user identifier. This way I can match a generated notification with a signalr client.
At the moment, I'm hosting the SignalR hubs within the IIS process. So how do I get back from the Windows Service to IIS to notify the client when a notification is generated?
Furthermore, I should say I am already using SignalR elsewhere in the application and am using a SQL Server backplane.
The issue's with the current architecture:
Any processing is done in the same web request, and notifications are sent out via SignalR before a response to the client is returned. Luckily, the processing is minimal and very quick.
I think this is not very good in terms of performance or maintenance in the long run.
Potential solutions:
Remove SignalR hubs from IIS and host them somewhere else - windows service?
Expose an endpoint on the API to for the windows service to call to push the notification once a notification is generated?
Finally, to add more ingredients to the mix: Use a service bus to remove the polling component of the windows service, and move to a pub/sub architecture. Although this is more work than I want to chew off right now.
Any ideas/recommendations/constructive criticisms are welcome.
Thanks.
Take a look at this sample for starters
Another more advanced solution can be using a backplane to manage the communications between the front end and the backend...
HTH

Should I use a different certificate for the APNS HTTP2 API?

Recently, I want to change my codes of pushing notifications to apple from basing on old binary API to new http2 API. The question is that should I use a different certificate for this http2 API when I connect to apple ? Because when I send a notification to apple with a valid token(the token is valid when I send notifications with old API) using http2 API, it returns "BadDeviceToken". So I'm wondering whether the token is really bad or the certificate that I use is not qualified .
We were also trying to break our heads with such an issue where we were trying to send push to production device tokens using the HTTP/2 API but were getting {"reason":"BadDeviceToken"} as the response and it was a clear mistake from our side, we were using the same code that we were using for test push notifications on dev environment to send push notifications on production, which was sending push to
https://api.development.push.apple.com/3/device/
rather for production it should be
https://api.push.apple.com/3/device
Hope it helps somebody but one issue with the new API is the distribution SSL certificate works for both the sandbox and production, not the other way round so be careful.
You can still use your old certificate with the new HTTP/2 API.
The BadDeviceToken is most commonly because you are trying to push through their production gateway wth a development token or vice versa.
Tokens are only valid for either development or production, and this is determined by the provisioning profile of your app.

Send Push Notifications Through Proxy (APNs and GCM)

I have built both ios and android apps which will receive push notifications. The problems are NOT from device side but from server side.
Because our company's internal server must connect to external network through Proxy, when users send notifications to mobile devices, the server which handles sending notification request must send request to proxy server then proxy server forwards request to APNs and GCM.
I have no idea about how to send push notification requests through proxy. I have studies in this case for several days, but no solutions have been found.
I saw some guys said APNs does not allow connections coming from Proxy Server. Only direct connection is accepted. Is that true? Is there any official docs mentioned it?
Is there anyone able to help me?
I wanna know how to send push notification through proxy for ios and android.
If you are using Java.You can use javaApns enter link description here for ios. I my self have problem right now to get GCM to send through proxy on my Server local it works. If you can you can configure the application server to send through proxy.

Can you not just send one push notification to Apple's Newsstand?

We are developing a Newsstand app, and are currently working on the push notification to let users know a new issue has arrived. From the ambiguous Apple documentation it looks like we will need to send a separate push notification for each user that downloaded the app; each notification should contain a unique device token for each app instance.
The section titled Trust Components seems to imply that you can use the device token or the certificates to authenticate your push notification, but it also implies you need both.
Is it correct that we will need to send out a separate push notification for each installed instance? Can we really not send one push notification and have Apple notify all the users of the app that a new issue has arrived?
Short answer is YES the statement you made is correct.
You have to send out push notification to each device token which must be stored in your server (provider). The preferred way to send multiple notification is to not make multiple connections but reuse one to send multiple notifications. Below is the paragraph from Apple Doc
You should also retain connections with APNs across multiple
notifications. APNs may consider connections that are rapidly and
repeatedly established and torn down as a denial-of-service attack.
Upon error, APNs closes the connection on which the error occurred

Resources