Support Topics Documentation Slack YouTube Blog

Notifications while app is closed

I believe I setup my app per the instructions, and I can’t for the life of me figure out why I don’t receive notifications if app is closed. If you could point me in the general area of where to look to get this resolved, it would be greatly appreciated!

Hi, @Robert_Dial

What do you mean by “closed app”? Is it in background, removed from recent apps or force-stopped?
If your app is in background you should receive the notifications from Backendless. In other cases there may be different issues. For example, battery saver can block notifications etc.
Please also make sure that you enable notifications in your app settings.

Best Regards,
Maksym

App closed, meaning removed from recent apps, my apologies. Notifications come in if app is running in the background or foreground.

How do you send the notifications? Feel free to write the sample code.

Best Regards,
Maksym

Notifications are sent from iOS device

Here is the code used.

func publishPushNotification(message: String) {
            let publishOptions = PublishOptions()
            publishOptions.assignHeaders(["ios-alert-title":alertMessageTextField.text ?? "bestbet",
                                          "ios-alert-body":notificationBodyTextView.text ?? "bestbet",
                                          "ios-sound":"default"])
        let deliveryOptions = DeliveryOptions()
        deliveryOptions.pushBroadcast(FOR_IOS.rawValue & FOR_ANDROID.rawValue)

            backendless?.messaging.publish( "default", message:message, publishOptions:publishOptions, deliveryOptions:deliveryOptions,
            response: {
                (status: MessageStatus?) -> Void in
                print("Status: \(String(describing: status))")
        },
            error: {
                (fault: Fault?) -> Void in
                print("Server reported an error: \(String(describing: fault))")
        })
    }

Hi, @Robert_Dial

Thanks for the details. We will try to reproduce your issue and will inform you of the progress.
One more question: do you send notifications from iOS and receive it in Android?

Best Regards,
Maksym

Yes. The only way I send notifications is from an iOS device. They are sent to both Android and iOS.

Thanks again for taking look at this!

Any ideas on what could be causing this?

Any response at all would be great…

Hi Robert,

Just to clarify the problem definition: are the push notifications not displayed when the app is closed on iOS or Android devices?

Also, the sample code you shared does not have any headers for Android, however, you mentioned you are targeting Android devices. Could you please clarify that as well?

Regards,
Mark

The push notifications are not displayed only on Android devices when closed.

I only target devices for testing purposes currently both on iOS and Android. I get the same results when the notification is pushed out to all.

Will add headers to see if that resolves the issue. I haven’t added headers because the notifications are being pushed if the app was running foreground or background.

The problem only occurs when the app has been closed out of recent apps.

I have it working now, just added a class for device registrations. Called the registration class inside Application in the manifest and it appears to be doing what it is supposed to now. I was doing the device registration as part of another class.

Thank you taking a look!