FCM Message not Received on iOS App when sent to a topic - c#

I want to send notifications with FCM to an iOS App. It works fine when I send it to the token, but it doesn't work when I send it to a topic. I tried subscribing the App to the topics using this:
string[] topics = { "all", "test" };
CrossFirebasePushNotification.Current.Subscribe(topics);
(This is using the Plugin.FirebasePushNotification) or using this:
string[] tokens = { e.Token };
FirebaseMessaging.DefaultInstance.SubscribeToTopicAsync(tokens, "test");
FirebaseMessaging.DefaultInstance.SubscribeToTopicAsync(tokens, "all");
(This is using FirebaseAdmin) It's both in the App.xaml.cs, the first one beeing under InitializeComponent(); and the second one beeing in OnTokenRefresh. It works fine on android, but not on iOS. Keep in mind, that e.Token is the Token. I even tried to subscribe in the AppDelegate.cs, but it didn't work there either. I think it could be because it tries to subscribe before I even said "Yes" on the device so it can send me Notifications. I'm using an iPhone SE with iOS 15.3.
Thanks for your help!

I figured it out. In the AppDelegate.cs you can override the RegisteredForRemoteNotifications and you can just subscribe there. This means, it will subscribe if the user grants the permission to send remote notifications. After that it worked perfectly.

Related

Using ALAssetsLibraryChangedNotification in background with Xamarin iOS

I am writing an app targeting iOS7 in Xamarin.iOS that is supposed to upload users' pictures to an online storage service as soon as he/she takes them. In order to do this, I set up an ALAssetsLibraryChangedNotification observer, like this:
NSNotificationCenter.DefaultCenter.AddObserver (ALAssetsLibrary.ChangedNotification, Callback);
and then defined a callback like this:
void Callback (NSNotification notification)
{
Console.WriteLine ("Received a notification ALAssetsLibrary : {0}", notification);
//Launch picture upload here
}
This works well, but only with the app open. Is there a way to make my app receive the notification (and process the upload) when it is backgrounded? I use iOS7 backgrounding for file transfers and long running tasks in other points of my app, but I wouldn't know how to apply this to the observer.
Extra question, I would also like to be able to filter out notifications received by this function so that I can launch my upload only if the operation is "new picture created" (currently I get notifications also when pictures are removed/edited/moved).
Thanks in advance for your replies :)

PushSharp notifications to iOS are not reaching device

I am attempting to use the PushSharp library for apple push notifications in a c# service I am running.
The code all appears to execute correctly, there are no errors and it seems all things are done correctly. However the notification never reaches my application.
Everything Ive read seems to conclude the issue is my certificate, but ive re-downloaded, and redone the steps numerous times and everything seems to be correct with it.
Here is my PushSharp c# code
string pushCertPath = string.Format(string.Format("{0}\\PushCert (DEV).p12", dataPath));
var appleCert = File.ReadAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, pushCertPath));
PushBroker push = new PushBroker();
push.RegisterAppleService(new ApplePushChannelSettings(false, appleCert,"pushcert"));
push.QueueNotification(new AppleNotification()
.ForDeviceToken("594c78b070698ded0a5f3dc1503a42e3983b7c1d254b61a98cc6e5eb0e8b7edd")
.WithAlert("You have received new messages")
.WithSound("default")
.WithBadge(1));
I got the same problem too since from yesterday. I just tried change the SslProtocols from SslProtocols.Ssl3 to SslProtocols.Default make it works again. So Apple must change something and refuse the Ssl3 protocol.
stream.AuthenticateAsClient(settings.FeedbackHost, certificates, System.Security.Authentication.SslProtocols.**Default**, false);

httpnotificationchannel same ChannelUri from two different apps in emulator

I'm new to windows phone development and have started working with push notifications within the emulator in visual studio 2012. We are having a strange problem where we have two apps in visual studio and when we start each one and call the following:
CurrentChannel = HttpNotificationChannel.Find("ChannelName");
if (CurrentChannel == null)
{
CurrentChannel = new HttpNotificationChannel("ChannelName");
CurrentChannel.Open();
CurrentChannel.BindToShellTile();
CurrentChannel.BindToShellToast();
}
Even though the ChannelName is different in each app the CurrentChannel.ChannelUri is the same so when we send push notifications they only go to one app.
I am sure we are missing something very obvious or misunderstanding the way this is supposed to work but any insight would be appreciated.
I supposed you didn't get the right Uri according to your piece of codes. Try to Listen on ChannelUriUpdated event to get a fresh Uri.
If you did, maybe try it on a real device, emulator is not always to be trusted enough.
And Push notification channel URi is unique for device & app combination, to be sure you made something different in these two apps. Anyway seems this couldn't be happened.

Push Notifications with PushSharp - the basics

I need to push notifications to tens of thousands of iOS devices that my app installed. I'm trying to do it with PushSharp, but I'm missing some fundamental concepts here. At first I tried to actually run this in a Windows service, but couldn't get it work - getting null reference errors coming from _push.QueueNotification() call. Then I did exactly what the documented sample code did and it worked:
PushService _push = new PushService();
_push.Events.OnNotificationSendFailure += new ChannelEvents.NotificationSendFailureDelegate(Events_OnNotificationSendFailure);
_push.Events.OnNotificationSent += new ChannelEvents.NotificationSentDelegate(Events_OnNotificationSent);
var cert = File.ReadAllBytes(HttpContext.Current.Server.MapPath("..pathtokeyfile.p12"));
_push.StartApplePushService(new ApplePushChannelSettings(false, cert, "certpwd"));
AppleNotification notification = NotificationFactory.Apple()
.ForDeviceToken(deviceToken)
.WithAlert(message)
.WithSound("default")
.WithBadge(badge);
_push.QueueNotification(notification);
_push.StopAllServices(true);
Issue #1:
This works perfectly and I see the notification pop up on the iPhone. However, since it's called a Push Service, I assumed it would behave like a service - meaning, I instantiate it and call _push.StartApplePushService() within a Windows service perhaps. And I thought to actually queue up my notifications, I could do this on the front-end (admin app, let's say):
PushService push = new PushService();
AppleNotification notification = NotificationFactory.Apple()
.ForDeviceToken(deviceToken)
.WithAlert(message)
.WithSound("default")
.WithBadge(badge);
push.QueueNotification(notification);
Obviously (and like I already said), it didn't work - the last line kept throwing a null reference exception.
I'm having trouble finding any other kind of documentation that would show how to set this up in a service/client manner (and not just call everything at once). Is it possible or am I missing the point of how PushSharp should be utilized?
Issue #2:
Also, I can't seem to find a way to target many device tokens at once, without looping through them and queuing up notifications one at a time. Is that the only way or am I missing something here as well?
Thanks in advance.
#baramuse explained it all, if you wish to see a service "processor" you can browse through my solution on https://github.com/vmandic/DevUG-PushSharp where I've implemented the workflow you seek for, i.e. a win service, win processor or even a web api ad hoc processor using the same core processor.
From what I've read and how I'm using it, the 'Service' keyword may have mislead you...
It is a service in a way that you configure it once and start it.
From this point, it will wait for you to push new notifications inside its queue system and it will raise events as soon as something happens (delivery report, delivery error...). It is asynchronous and you can push (=queue) 10000 notifications and wait for the results to come back later using the event handlers.
But still it's a regular object instance you will have to create and access as a regular one. It doesn't expose any "outside listener" (http/tcp/ipc connection for example), you will have to build that.
In my project I created a small selfhosted webservice (relying on ServiceStack) that takes care about the configuration and instance lifetime while only exposing the SendNotification function.
And about the Issue #2, there indeed isn't any "batch queue" but as the queue function returns straight away (enqueue and push later) it's just a matter of a looping into your device tokens list...
public void QueueNotification(Notification notification)
{
if (this.cancelTokenSource.IsCancellationRequested)
{
Events.RaiseChannelException(new ObjectDisposedException("Service", "Service has already been signaled to stop"), this.Platform, notification);
return;
}
notification.EnqueuedTimestamp = DateTime.UtcNow;
queuedNotifications.Enqueue(notification);
}

Windows phone 7 toast notification

in toast message in windows phone 7, when clicking on that message the
application opens thats fine,
i just want to navigate to specific page when the toast message is clicked,
is there any way to do it?
both in 7 and mango update???
or
in http://samidipbasu.com/2011/06/14/push-notification-payloads/ in this link when we read for toast notification, we have an extra parameter called wp:Param in xml format to send. How they were sending this wp:Param data in windows 7.0(before mango update). Any idea ??
Support for navigating to a particular page is supported in Mango. Below is an example that does not require an HTTP channel, but must be executed by a background agent (not the application itself):
var toast = new ShellToast
{
Title = "Title",
Content = "Toast content",
NavigationUri = new Uri("/SomeOtherView.xaml", UriKind.Relative)
};
toast.Show();
NOTE: The NavigationUri functionality is also supported by toast sent via HTTP push notifications
#curiosity .. Toast & Tile payloads are pre-defined so that the OS can process these bits coming from MPNS after your app registers shellToast/shellTile. The extra parameters in the payloads are supposed to supported starting with Mango. As your app's first page (or whichever XAML page is in the URL) launches from the deep-toast, the developer should be able to listen in on the OnNavigatedTo() event to do something special with the params in the incoming URL (query string). Please see some later posts on my blog for examples & let me know if it helps.
Thanks!
all the info you need to know about push notifications is here

Categories