Push Notifications in Mavericks iOS Simulator
Asked Answered
V

7

32

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.

Vday answered 12/2, 2014 at 22:30 Comment(2)
FYI, Local Notifications in iPhone simulators work just fine now.Motherwort
It’s finally possible! https://mcmap.net/q/195254/-how-can-i-test-apple-push-notification-service-without-an-iphoneLallage
H
15

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.

Hypethral answered 6/2, 2020 at 5:7 Comment(2)
Also you can do it by using terminal. Simply enter this command : xcrun simctl push <simulatorDeviceIdentifier> <pathTopayloadfile>Runesmith
The simulator can't receive real push notifications from APNs, it only supports simulating remote push notifications.Listel
C
41

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

Chesney answered 20/9, 2014 at 0:0 Comment(6)
No, it's just related to iOS8+, I test with iPhone 5 simulator with iOS 8, the notification alert is also pop up.Philistine
Thank you or this. But how do you get the Device Token in Simulator ? I still receive the message : "ailed to register with error : Error Domain=NSCocoaErrorDomain Code=3010 "remote notifications are not supported in the simulator" UserInfo=0x7fefba842250 {NSLocalizedDescription=remote notifications are not supported in the simulator} "Particulate
No - no third party product beside a couple of libraries and SDKsParticulate
@SébastienStormacq any luck with this? I also receive the 'failed to register...' error, even though they appear to be supported in iPhone 6 and 6+.Dixson
No I still receive "remote notifications are not supported in the simulator" I don't know how this guy managed to have this working. I found no other post / article on the internet that explains this. Only here :-(Particulate
This answer is talking about Local notifications, not Remote (aka "Push") notifications. "Local Notifications" refers to the UI that you see on your notifications screen and can be triggered by local code. True Push Notifications, refers to a kind of network activity, and may or may not have a notification on your notification screen. So, though there is support for Local notifications on older versions of iOS, true Push notifications are not supported until iOS10 on the simulator. Shame on Apple for having such confusing terminology. More: https://mcmap.net/q/445530/-push-notifications-in-mavericks-ios-simulatorFarris
L
25

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

Latvia answered 12/2, 2014 at 22:37 Comment(1)
I have to use four different real devices to make screenshots? iPhone 6.5" Display, iPhone 5.5" Display, iPad Pro (3rd Gen) 12.9" Display, iPad Pro (2nd Gen) 12.9" DisplayPretonic
M
19

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.

Maidinwaiting answered 15/10, 2014 at 19:0 Comment(2)
Yeb, everyone has known that use real device is the best, but I'm a new IOS Developer and I can't effort to buy many device, so I have to use simulator to test my app, I only have iphone 4 and other device it's too expensive :(Tempura
Isn't one device enough to make sure your response to notifications works as expected?Keratinize
H
15

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.

Hypethral answered 6/2, 2020 at 5:7 Comment(2)
Also you can do it by using terminal. Simply enter this command : xcrun simctl push <simulatorDeviceIdentifier> <pathTopayloadfile>Runesmith
The simulator can't receive real push notifications from APNs, it only supports simulating remote push notifications.Listel
F
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);
}
Farris answered 5/7, 2016 at 18:59 Comment(2)
Thanks for the update. That's good to hear. I'll let my friends know...Vday
Does not seem to work in xcode 8 beta4 and 5. I get UserInfo={NSLocalizedDescription=remote notifications are not supported in the simulator} in application:didFailToRegisterForRemoteNotificationsWithError. The simulator is 5s and 10.0.Intermit
P
3

Looking forward to using remote notifications in the simulator when iOS 10 comes out.

In the meantime I use the Xcode command line to test notification behavior:

p [((CustomAppDelegateClass *)((UIApplication *)[UIApplication sharedApplication]).delegate) application:[UIApplication sharedApplication] didReceiveRemoteNotification:@{@"aps": @{@"alert": @"Alert Message"}, @"info": @{@"object": @"value"}}];
Pushover answered 17/7, 2016 at 17:55 Comment(4)
When I try to run this I get : -bash: syntax error near unexpected token `('Coadjutress
@GuybrushThreepwood: i haven't tried it, but i believe this command is to be entered into the lldb debug console during debugging, in Xcode.Kannry
@Coadjutress Right, after running the simulator you can "Pause program execution" then enter this command next to the "(lldb)" in the log output.Pushover
out of curiosity I tried push notifications in iPhone 7 emulator (iOS 10.1, 14B72) but they are not working there.Soulier
L
3

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

Step 1 :- Create Project (Xcode 11.4 beta)

Step 2 :- import UserNotifications and registerForPushNotifications

Step 3 :- Create JSON file (payload.apns) like below

{
    "Simulator Target Bundle": "metiz.DemoSimPushnotification",
    "aps": {
        "title": "Xcode 11.4 Beta Update",
        "alert": "Push notification in simulator - take a look",
        "sound": "default",
        "badge": 1
    }
}

Step 4 :- Open terminal write command $ xcrun simctl push com.example.myapp ExamplePush.apns”

< device > will be replaced by the device identifier.

com.example.myapp  will be replaced by your project’s bundle identifier

ExamplePush.apns will be replaced by the filename of our apns file.

like this:-

$ xcrun simctl push 4F19A097-DAE2-4298-99EB-23D4F2DBAF97 metiz.DemoSimPushnotification payload.apns

Now, press Enter! see the magic!

Reference link:-

https://www.metizsoft.com/blog/testing-push-notification-on-ios-simulator

Longitudinal answered 18/2, 2020 at 13:33 Comment(2)
Here is how to get emulator device ID: i2.wp.com/www.metizsoft.com/wp-content/uploads/2020/02/…Antipathy
you forgot to put < device > in your step 4, and you didn't format the response perfectly. Too bad because your answer is perfect !Membrane

© 2022 - 2024 — McMap. All rights reserved.