Push Notifications in Mavericks iOS Simulator

57,327

Solution 1

Yeahhh!! With the release of XCode 11.4, Now it is possible to receive Push notification in Simulator too. Apple's latest release says,

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.

Reference Link: https://developer.apple.com/documentation/xcode_release_notes/xcode_11_4_beta_release_notes

Example payload file,

{
    "Simulator Target Bundle": "com.yourOrganization.appName",
    "aps": {
        "alert": "This is a test notification!",
        "badge": 5,
        "sound": "default"
    }
}

@note: mention your application's Bundle Identifier in "Simulator Target Bundle" in the above Payload.

Dragging and dropping above json file onto the target simulator will present the notification and set the badge.

Solution 2

iOS 8 and Xcode 6 did indeed add some additional integration to push notifications. If you select the iPhone 6 or iPhone 6 Plus simulator your app will now appear under Settings with a full featured notifications settings screen (see attached) and will show the in app modal when requesting push notification permissions for the first time. This is only true for the iPhone 6 and iPhone 6 Plus simulators.

Screenshot 2

Screenshot 1

Screenshot 3

However, in iOS 8 you will still get message in console as 'remote notifications are not supported in the simulator' and hence you have to use device only.

Screenshot 4

Solution 3

No, there is still no API to support push notifications in the simulator. You’ll have to use a device.

Solution 4

Even though iPhone 6 and iPhone 6+ simulators have setting for push notifications and even show you the push notification prompt, an attempt to register for push notifications from simulator still fails with Error Domain=NSCocoaErrorDomain Code=3010 "remote notifications are not supported in the simulator" UserInfo=0x7fc786b4af90 {NSLocalizedDescription=remote notifications are not supported in the simulator}. So, your best bet is still to use a device.

Solution 5

Update XCode8 GM Release

Log: Push notifications now fail with the old haunting poem:

remote. 
notifications are not.
supported in the simulator.

I now question myself and my sanity. This feature that I'd long hoped for, and for a brief moment had in my hand, or so I thought. Was it all just a dream? Are any of us really here?

<fade out...>

Original Post

As of the iOS10 beta (XCode Version 8.0 beta (8S128d)), simulators seem to be getting Push notifications. Note that although prior to iOS10, devices could receive local notifications, they did not receive push notifications.

I don't have any official source on this, just anecdotally, features that rely on push notifications which used to fail, are now succeeding on iPhone 5, 5s, 6, 6+ simulators.

I also verified that we're hitting the registration block in AppDelegate.

- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
  NSLog(@"Successfully registered!");
  doSomething(notificationSettings);
}
Share:
57,327
sudo
Author by

sudo

yo

Updated on April 11, 2020

Comments

  • sudo
    sudo about 4 years

    I can't find anything about this, and I have never done anything with push notifications (but I know vaguely how they work). In Mavericks, now that OS X can receive push notifications from various things like websites, can iPhone Simulator receive push notifications? I've found plenty of answers from mid-2013 and earlier saying "no", but all of them are outdated because Mavericks was just recently released with its new push features.

    I'm about to start working on an app for a school project that should use push notifications unless I want to be cheap and just poll the server. I understand that you NEED an iOS developer account to use push notifications, but it would make my life a lot easier if I could test on my computer.