Xcode 8 ios 10 Simulator , is it possible to send push notification to the simulator
Asked Answered
A

5

9

My app uses Firebase. I am trying to send push notification to app running in simulator. When I run the app in iOS 10 Simulator, it successfully generates InstanceID token but shows warning that

notifications are not supported in the simulator.

I read somewhere on stackoverflow that it is possible to send push notification on iOS 10 simulator. Is it true?

Any answered 9/11, 2016 at 20:36 Comment(1)
I think I have read the post. However when I tried, I couldn't get any push notification in iOS 10 simulator and I don't think there's a way. I googled for a second and found this. Not sure it is working or not.github.com/acoomans/SimulatorRemoteNotificationsEctomere
A
7

You cannot get push notifications inside the simulator. You can, however simulate getting a push notification by making a button or whatever that calls application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) with a notification dictionary. This is useful for testing that the rest of your logic is working before you deploy to device to test that the final format of the push is what you expect it to be.

Adolphus answered 9/11, 2016 at 22:30 Comment(1)
meaning you can only simulate notifications that come when the app is running and in the foreground?Venison
H
4

Two things:

  • You cannot test push notification in simulator. So you have to test only in iPhone device only. Additional information: If you wan to test the push notification locally in your device try using Test push notification

  • You said you heard somewhere that " it is possible to send push notification on iOS 10 simulator". It is not true, The thing is in iOS 10 you can view the local notification even when the app is in foreground. using the following delegate method "willPresentNotification" supported from iOS 10. Which you can test in simulator.

Heliotype answered 12/11, 2016 at 8:7 Comment(0)
W
2

Now It Is Possible!!!

The Xcode 11.4 beta is released with simulator supporting remote push notifications.

To test remote push simply dragged APNS file onto the target simulator. This method required the payload to contain Simulator Target Bundle key. Otherwise, you would get this error message.

“Invalid push notification: The file does not contain a valid JSON payload or the Simulator Target Bundle key is missing."

So your payload file will be like:

{
       "aps" : {
        "alert" : {
            "title" : “Namaste”,
            "body" : “This is iOS development notification test“
        },
    },
    "Simulator Target Bundle": "com.sarunw.example-xcode-11-4"
}

Following simctl command in terminal will help to sent notifications:

xcrun simctl push <device> <bundle-identifier> <path-to-apns-file>
Wellbred answered 13/2, 2020 at 11:2 Comment(0)
C
0

From onward Xcode 11.4 Beta you can test push notifications on iOS simulator. The Xcode 11.4 Beta release notes

The simulator supports simulating remote push notifications, including background content fetch notifications. In Simulator, drag and drop an APNs file onto the target simulator. The file must be a JSON file with a valid Apple Push Notification Service payload, including the “aps” key. It must also contain a top-level “Simulator Target Bundle” with a string value matching the target application‘s bundle identifier.

Caesar answered 7/2, 2020 at 7:13 Comment(0)
H
0

Now it is possible to receive a Push notification (with sound and badge count) in Simulator

click here https://mcmap.net/q/445530/-push-notifications-in-mavericks-ios-simulator

Hussite answered 18/2, 2020 at 13:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.