0

I am developing an iOS app in SwiftUI and using Firebase to send push notifications.

Now the push notification works fine in real device (my iPhone 11 with iOS 16.3.1). My iPhone can receive push notifications by sending test messages via Firebase console.

However, with the same code & configuration (without modifying anything), just change Xcode target from my iPhone to a simulator and run it, the simulator cannot receive any push notification by sending test messages via Firebase console.

From my log, the only difference I see is... the following function doesn't get called when testing on simulators (it is called when testing on my iPhone)

func application(_ application: UIApplication, 
                 didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    print("APNs device token: \(deviceToken)")
    Messaging.messaging().apnsToken = deviceToken
}

I've tried a few things like:

  • make my iPhone and my Mac connect to the same Wifi
  • delete a simulator and add it back
  • try different iPhone simulators (iPhone 14, iPhone 11, etc.)

Noting resolves the issue. Could anyone shed some lights on this? XCode is 14.2

Joe Huang
  • 6,296
  • 7
  • 48
  • 81
  • Push notifications don't work in the simulator. See https://stackoverflow.com/questions/1080556/how-can-i-test-apple-push-notification-service-without-an-iphone/60085404#60085404 – jnpdx Feb 25 '23 at 03:17
  • @jnpdx Thanks for bringing it up, I probably know why then, but Push notifications can work on simulators with XCode 14 plus some conditions to be met, please see the release notes of XCode 14: https://developer.apple.com/documentation/xcode-release-notes/xcode-14-release-notes – Joe Huang Feb 25 '23 at 03:42
  • "Simulator now supports remote notifications in iOS 16 when running in macOS 13 on Mac computers with Apple silicon or T2 processors. Simulator supports the Apple Push Notification Service Sandbox environment. Your server can send a remote notification to your app running in that simulator by connecting to the APNS Sandbox (api.sandbox.push.apple.com). Each simulator generates registration tokens unique to the combination of that simulator and the Mac hardware it’s running on. " – Joe Huang Feb 25 '23 at 03:42
  • I will see if I can get a Mac with Apple silicon or T2 processors and test again. If it works, I will post an answer. – Joe Huang Feb 25 '23 at 03:43

2 Answers2

0

Make sure that you have at least Firebase 10.3. Before that, Firebase did not support push notifications on the simulator.

Paul Beusterien
  • 27,542
  • 6
  • 83
  • 139
0

For the Mac computer, you need one with Apple silicon or T2 processors:

If your Mac's CPU starts with an M, you are good or you must have a Mac computer that has Apple T2 Security Chip:

iMac (Retina 5K, 27-inch, 2020)
iMac Pro
Mac Pro (2019)
Mac Pro (Rack, 2019)
Mac mini (2018)
MacBook Air (Retina, 13-inch, 2020)
MacBook Air (Retina, 13-inch, 2019)
MacBook Air (Retina, 13-inch, 2018)
MacBook Pro (13-inch, 2020, Two Thunderbolt 3 ports)
MacBook Pro (13-inch, 2020, Four Thunderbolt 3 ports)
MacBook Pro (16-inch, 2019)
MacBook Pro (13-inch, 2019, Two Thunderbolt 3 ports)
MacBook Pro (15-inch, 2019)
MacBook Pro (13-inch, 2019, Four Thunderbolt 3 ports)
MacBook Pro (15-inch, 2018)
MacBook Pro (13-inch, 2018, Four Thunderbolt 3 ports)

And make sure your Firebase SDK is 10.3.0 or above. If you use older version, you will see a log saying

Running InstanceID on a simulator doesn't have APNS. Use prod profile by default.

when you assign APN to Firebase.

With above two things, XCode simulators can receive remote push notifications successfully even with multiple instances.

Joe Huang
  • 6,296
  • 7
  • 48
  • 81