Push notifications from firebase in iOS simulator

Viewed 1845

I have an app that uses cordova-plugin-firebasex for the push notifications. But they don't appear in notification center while app is in the background. I'm using iOS simulator in XCode.

Can I test Firebase notifications in simulator while app is in the background? Or I need real device for this?

2 Answers

Simulators are not supporting push notifications. You can see this output text from Firebase SDK in yuor console output Like

6.27.0 - [Firebase/Messaging][I-FCM012002] Error in application:didFailToRegisterForRemoteNotificationsWithError: remote notifications are not supported in the simulator

You can actually test the notifications locally using the XCode Simulator Control Utility:

xcrun simctl push booted payload.json

with the following payload stored in the JSON file in your local directory:

{
    "aps": {
        "alert": {
            "title": "Local notification test",
            "body": "This is the body of your local notification."
        }
    },
    "Simulator Target Bundle": "com.example.example"
}

Where the com.example.example is your bundle identifier.

For more information have a look at the utility's documentation:

xcrun simctl push --help
Related