Sending IOS notifications from Firebase (or another platform) to specific terminales - swift

We are currently able to send notifications to specific Android devices through Firebase and I am trying to do the same to IOS devices.
We use POD and have installed
pod 'Firebase/Core'
pod ‘Firebase/Messaging'
We've created an account with Firebase.
I have added the functions that correspond to AppDelegate.swift. After executing the app, I can send notifications from Firebase to all iPhones... but no specific ones.
In production, I have the following
FIRInstanceID.instanceID().setAPNSToken(deviceToken, tape: FIRInstanceIDAPNSTokenType.prod)
Up to here, all good .. but when I try to get the token from a user and then send a notification only to that device... the notification does not arrive
The token is generated without any problems.
if let refreshedToken = FIRInstanceID.instanceID().token() {
print(“InstanceID token: \(refreshedToken)”)
}
From firebase The notification is sent and does not show errors.. but the notification never arrives to the actual device.
Can this be done with Firebase?
Is there any other service that would allow me to do this?
UPDATE
I send message for console
click open image

On Android, Firebase has the luxury of using GCM directly. For Apple, FCM messages need to be sent to Apple Push Notifications.
Make sure you have setup the backend by downloading your APN Key and uploading to your Firebase console:
Download: https://firebase.google.com/docs/cloud-messaging/ios/certs
Upload: Open your Firebase console, click on the gear icon in the upper left, click on Project settings and then the Cloud Messaging Tab. Upload your APN key there.
You should be able to grab the FCM device ID from the debug output console when Firebase starts up (when running the app in debug mode).

You need to update your Firebase pod and add code from this answer to your iOS Application-
Working Firebase Messaging Code for iOS App

Related

I already get fcm key of ever users,How to send notification to another user with firebase cloud messaging?In dart

I have Fcm key
and working when i put fcm trial of cloud messageing in firebase
I tried but only got same device notification,
I am expecting that when I send a message to another user The other user need to get a notification while the app is not opened

Independent Watchkitapp APNS push notification successful send but notification does not receive in Apple Watch

I have created an independent watchkitapp in XCode, installed in apple watch and successfully sent push notification without errors from Pusher app (also in node-apn) but the notification does not arrive in app. (Tried another app for iOS and remote push notification successfully received in iOS app)
These are the steps i took
In my watchkitapp I did WKExtension.shared().registerForRemoteNotifications() and took the device token
UNUserNotificationCenter.current().requestAuthorization and allowed push notification on apple watch. ofcourse I set UNUserNotificationCenter.current().delegate to the InterfaceController (I tried Local Notification and local notifications display normally on the watch)
On XCode watchkitapp.watchkitextension I added Push Notification on capabilities
In Apple Developer page I created app id mirroring the watchkitapp bundle (not the watchkitextension one). In my case apple automatically created App Id in the server but I removed and recreated it to make sure
Checked the Apple Push Notification service and generated Development SSL Cert
Downloaded the Development SSL Cert and installed in keychain
Opened the Pusher app and selected the installed Development SSL Cert from the list. Ran the apple watch app and obtained the Token Id... sent the payload and it says the payload is sent
Tried to restart mac, iphone, apple watch, unpairing apple watch, reinstalling app but the result is the same... push is sent but does not receive in apple watch
anybody can help me how can I fix this?
Finally, I got this successfully. I use node-apn to send from server.
Here are the worth noticing things:
create app id of the watchkitapp bundle in Apple Developer page
install the latest version of: node-apn,
"dependencies": {
"apn": "git+https://github.com/node-apn/node-apn.git#3.0.0",
[...]
}
should set apns-push-type
notification.pushType
(Required when delivering notifications to devices running iOS 13 and later, or watchOS 6 and later. Ignored on earlier system versions.)
The type of the notification. The value of this header is alert or background. Specify alert when the delivery of your notification displays an alert, plays a sound, or badges your app's icon. Specify background for silent notifications that do not interact with the user.
The value of this header must accurately reflect the contents of your notification's payload. If there is a mismatch, or if the header is missing on required systems, APNs may delay the delivery of the notification or drop it altogether.

ionic 3 onesignal handle when notification received

I just started to use OneSignal push notifications system, and I have one problem when I should make some action when user receive notification. I use in my app same code as on Ionic documentation:
this.oneSignal.startInit('my-one-signal-id', 'firebase-id');
this.oneSignal.inFocusDisplaying(this.oneSignal.OSInFocusDisplayOption.InAppAlert);
this.oneSignal.handleNotificationReceived().subscribe(() => {
// do something when notification is received
});
this.oneSignal.handleNotificationOpened().subscribe(() => {
// do something when a notification is opened
});
this.oneSignal.endInit();
Problem is that handleNotificationReceived function works only when I am in application, when app is killed doesn't work. On other hands handleNotificationOpened function works well even app is killed or run.
What I am trying to do is to save notification in local storage when notification is received. Can someone know how to do that and how to make handleNotificationReceived run even app is killed? Or how to get all unread notifications from OneSignal server (application back-end is out of reach to be changed) when user open application?
I am using Ionic 3, and app should be build in both Android and IOS.
Thanks in advance for answer.

iPhone doesn't receive notificatins in debug mode

We have a really weird problem with the remote notifications on iPhone. Device just doesn't receive remote notifications however registration works fine. We checked all certificates and also provisioning profile, also tried to send test notification directly from Azure, the same result as we send with our api. When app is installed from HockeyApp notifications works fine. In debug DidReceiveRemoteNotification method is just not called.
public override async void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
{
// Opened by push notification.
if (application.ApplicationState == UIApplicationState.Background || application.ApplicationState == UIApplicationState.Inactive)
{
// Make userInfo readable.
PushNotification notification = CrossDevice.Current.ConvertToNotification(userInfo);
}
// Process notification so we can attach to it's received event.
CrossAzurePushNotifications.Platform.ProcessNotification(userInfo);
// No data is altered.
completionHandler(UIBackgroundFetchResult.NoData);
}
Note: we are using AzurePushNotifications plugin
xamarin forum question
You should use the 'sandbox' for testing with the debugger attached. See this link or this link for more information about sandbox vs production.
Please also note that switching from production to sandbox in Azure NotificationHub does not always work. Best solution is to create a separate notification hub for test and production.
You need two Notifications Hub: one for testing and one for production.
If you are developing and running the App from Xcode, you have to use the testing Hub with a testing certificate and when you want to upload it to the Apple Store o TestFlight, you have to change the URL and use the Production Hub. If not, there is not woing to work.
You need different certificates, you can check the process here: https://learn.microsoft.com/en-us/azure/notification-hubs/notification-hubs-ios-apple-push-notification-apns-get-started
Here is when you decide what kind of certificate you have to choose: https://learn.microsoft.com/en-us/azure/includes/media/notification-hubs-enable-apple-push-notifications/notification-hubs-appid-create-cert.png

Testing Apple Push Notifications Feedback - no items received

How to test feedback.sandbox.push.apple.com? Everything goes right, but I receive empty list.
How to make it consider the device token as inactive?
I installed the application to iPhone using Xcode, received some push notifications, then removed it from iPhone and send some more notifications. But even on the next day feedback.sandbox.push.apple.com returns just empty set.
Issues with Using the Feedback Service
If you remove your app from your device and then send a push notification to it, you would expect to have the device token rejected, and the invalidated device token should appear on the feedback service. However, if this was the last push-enabled app on the device, it will not show up in the feedback service. This is because deleting the last app tears down the persistent connection to the push service before the notice of the deletion can be sent.
You can work around this by leaving at least one push-enabled app on the device in order to keep the persistent connection up. Just install any free push-enabled app from the App Store and you should then be able to delete your app and see it appear in the feedback service.
source:
http://developer.apple.com/library/ios/technotes/tn2010/tn2265.html#TNTAG34
I far as I found, Apple push notification feedback service doesn't work properly on sandbox mode. You should try it on ad-hoc or production mode.