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
Related
I'm writing a program in C# to get the system's public IP and inform the user of the new one if it changes. The problem is I have two ways of informing the user: Email or Cortana. For the first one (Email) I need an anonymous email sender that I don't have, or ask the user to provide his/her credentials (most people won't). Second way (Cortana): Let's say I have the program installed on my home PC and I have Cortana enabled on Windows 10 and a Windows Phone with Cortana. If my home PC's public IP address changed, Cortana will show a notification on my phone including my new IP address.
I saw an API on github (that can't do this) and Cortana for developers. I thought "actions" can do the job but after reading the descriptions I'm somehow sure that it can't.
How can I do that?
What I did:
I wrote a little program for Windows 10
https://www.microsoft.com/en-us/store/apps/remotecmd/9nblggh4vr31
and the server side app
http://naryhd.com/RemoteCMDServerBETA.zip
This app lets you have your PC's cmd on your windows phone. (locally)
Now I want to add "access from internet" to it, (I did that, but for security reasons I disabled it, now I got a more secure solution for it)
There are 3 things that I do for accessing it from the internet
Command 1:
netsh http add urlacl url=http://ip:port/ user=everyone
Command 2:
netsh advfirewall firewall add rule name=\"RemoteCMDserver2\" dir=in protocol=tcp localport=port profile=public | private remoteip=localsubnet action=allow
Forwarding that port:
var discoverer = new NatDiscoverer();
var cts = new System.Threading.CancellationTokenSource(10000);
var device = await discoverer.DiscoverDeviceAsync(PortMapper.Upnp, cts);
await device.CreatePortMapAsync(new Mapping(Protocol.Tcp, port, port, "REMOTECMD"));
I used open.nat from nuget to do port forwarding.
I use this code to get the PC's public IP:
var discoverer = new NatDiscoverer();
var device = await discoverer.DiscoverDeviceAsync();
var ip = await device.GetExternalIPAsync();
I save that IP in a text file, and repeat checking it every minute, and if it changes it will save that IP and send that IP to the user (currently via email) but I would like to send it with Cortana.
You can't do that with Cortana, as of right now. You can have a App, on the Phone, that displays a push Notification in the Action Center or on a Live Tile.
Here is some hopefully useful links:
Toast Notification and Action Center Overview for Windows 10
Inside Windows Platform | How to Add Push Notifications to Your App
I am developing a windows phone application and I could send a message to another windows phone device based on that device's channel uri.
public static HttpNotificationChannel pushChannel;
App.pushChannel = new HttpNotificationChannel(channelName);
App.pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);
void PushChannel_ShellToastNotificationReceived(object sender, NotificationEventArgs e)
{
//TODO:
}
I have below questions related to the above code:
How do I read the channelUri of the sender so that I can reply to the sender ? I see it is available in sender -> ChannelUri- > AbsoluteUri
And if sender wants to send more parameters can we add more toast xml tags apart from wp:Text1 and wp:Text2 or do we need to make use of wp:param only?
In scenario like Chat application should my code first store the channeluri of every device in some database and then when it wants to send a message to a particular user/device, it should read that particular user's channeluri based on his id or emailid ? Any other suggestion in this point on how to maintain users info for exchanging the messages ?
1.
You don't get the channel Uri, because they are not build for direct device to device communication. You have to transmit them by yourself.
2.
In a toast notification you only have these params available.
3.
Your application probably won't work without an extra server that manages the device/user/channel ids. Push Notifications are not made for direct device to device communication.
ChannelUris may change at any time, so your app has to send it to your server from time to time (recommended is on every start).
Also, notifications have a very limited payload, so you need to transfer the complete messages and user data on another way.
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.
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 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!