6 years
x
413 Views

How to Send Push Notifications to the iOS Simulator
As of Xcode 11.4 beta, you can!
Sagun Raj Lage
Sagun Raj Lage
Feb 10, 2020 · 6 min read
Image for post
Image for post
Photo by Jamie Street on Unsplash

Push notifications are one of the most popular ways for developers to keep users engaged in their apps. In iOS applications, push notifications can be incorporated by using the Apple Push Notification service (APNs).

However, it’s not as easy as it sounds since there is a long list of things to do for setting this up. Plus, what’s worse is that we have to use a real device to test if push notifications are working or not since push notifications aren’t supported in Xcode’s iOS Simulator.

But I have some good news for you. Xcode 11.4 beta is out and the best part about this release for me is that we can finally test push notifications in the iOS Simulator!

The release note of Xcode 11.4 beta consists of a section that 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.

simctl also supports sending simulated push notifications. If the file contains “Simulator Target Bundle” the bundle identifier is not required, otherwise you must provide it as an argument (8164566):

$ xcrun simctl push com.example.my-app ExamplePush.apns”

We’ll go in-depth about what this means in the latter part of the post. But for now, let’s be happy because the hassle of having to use a real device for testing push notifications is finally gone.
How Do We Do It?

So, now, let’s see how we can use this newly-arrived feature of Xcode 11.4 beta. For this, you obviously need to have Xcode 11.4 beta or higher. I currently have Xcode 11.4 beta.
Image for post
Image for post

Now, let’s create a new project. I’ve named it TestPushNotifications and the user interface I chose is Storyboard. You can choose SwiftUI if you want.
Image for post
Image for post
Creating a new project

Just to make the app look good (though it won’t help…), I’ve added a UILabel that says “Hello, world!” in View Controller of Main.storyboard.

Now, when we run the app in a simulator, iPhone 11 Pro Max in this case, it looks like this:
Image for post
Image for post

This is where the fun begins! Let’s go to the AppDelegate.swift file and add the following line below import UIKit to import Apple’s UserNotifications framework.

import UserNotifications

Now, in the AppDelegate class, let’s create a function, registerForPushNotifications(), that requests permission from the user to allow the app to send push notifications.
registerForPushNotifications() function that is added in the AppDelegate class

Let’s call the function we just created, from the application(_:didFinishLaunchingWithOptions:) method of AppDelegate.

For that, add registerForPushNotifications() above the return true statement. Your AppDelegate.swift file will look something like this:
Final version of AppDelegate.swift file

When we run the app, we get a dialog asking for permission to allow the app to send push notifications. Tap Allow.
Image for post
Image for post
Dialog asking for permission from the user to allow the app to send push notifications

The release note of Xcode 11.4 beta says:

“simctl also supports sending simulated push notifications. If the file contains “Simulator Target Bundle”, the bundle identifier is not required, otherwise, you must provide it as an argument (8164566):

$ xcrun simctl push com.example.my-app ExamplePush.apns”

Now, let’s try what it says. For that, we require a JSON file with a valid Apple Push Notification Service payload.

Apple’s documentation, entitled “Generating a Remote Notification”, gives a clear idea about how we can create such a file. I’m creating a file named notification.apns on my desktop and adding the following content in it:

After the file has been created, we can open the terminal and use the command given in the release note:

$ xcrun simctl push com.example.my-app ExamplePush.apns

Here, is to be replaced by the device identifier, com.example.my-app is to be replaced by your project’s bundle identifier, and ExamplePush.apns is to be replaced by the filename of our apns file.

Note that the bundle identifier is not necessary in the command, if you add it with the “Simulator Target Bundle” key in the apns file.

You can retrieve your simulator’s device identifier by following the steps shown in the GIF below:
Image for post
Image for post
Finding the device identifier of the simulator we are using (iPhone 11 Pro Max, in this case)

And you can retrieve the bundle identifier of your project by following the steps shown in the GIF below:
Image for post
Image for post
Finding the bundle identifier of the project

Before we execute the command, we have to send the app to the background first. That’s how the push notification will be visible.

Note: If you want the push notification to be visible even when the app is on the foreground, you can make AppDelegate conform to UNUserNotificationCenterDelegate and implement its userNotificationCenter(_:willPresent:withCompletionHandler:) method. And make sure that you have included the following line before calling registerForPushNotifications() in application(_:didFinishLaunchingWithOptions:) method:

UNUserNotificationCenter.current().delegate = self

Thanks to Rajan Maheshwari for his response.

Now, let’s execute the command. In my case, the command is:

$ xcrun simctl push 25A9FF1A-000B-4F36-B44C-43AC7BCD0958 np.***.sagunrajlage.TestPushNotifications notification.apns

As soon as it is executed, this is what we can see in the simulator — a push notification:
Image for post
Image for post
A push notification in Simulator

That’s how we can run a command to show push notifications in our simulator!

But wait, if you are not quite comfortable with using the terminal, there’s another way. Remember what the release note said?

“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.”

We can simply drag and drop our apns file into the simulator to get a push notification. But for that, we will have to make some modifications in the apns file.

In the notification.apns file that we created previously, let’s add one more key, “Simulator Target Bundle”, which will hold the value of our bundle identifier, which is “np.***.sagunrajlage.TestPushNotifications” in my case.

So, the file will look like this:

Now, drag and drop this file over to the simulator and see the magic!
Image for post
Image for post

And that’s another way to test push notifications in the iOS Simulator.

This is a great addition to the upcoming versions of Xcode because it saves us from a lot of hassle. Keep it up, Apple!

Shoutout to my mentors, Prakshapan Shrestha, Nutan Niraula and Ashwin Shrestha, for inspiring, encouraging, and supporting me!

Happy coding!

Medium

New Confession

Mr John…she stammered.shhhhh I said. If I tell your mom you were actually f****** on my couch she’ll beat you ground you or? Yeah I know. How can we make this right? Well if I won’t tell you can’t tell. Come over here and sit on my lap. No straddle my legs and face me. Are we going to really f***? No sweetie. You are 13, and I’m not insane. But a little foreplay to give you your o***** would be a nice way to end your night. She edged up to me , saw the huge bulge in my pants. And spread her thighs apart and nestled her tight little a** on my legs. God she was warm. I parted her blouse snd palm ribbed her n******. A minute later she closed her eyes and leaned backwards, her tongue lolling in her mouth. I Slowely began sucking and licking her now hardening n******. Slurp. Slurp. I suckled her tips. Oh oh Mr John you really know how to s*** n******. She panted. Now I ran my fingernails from her spread open knees to her very inner thighs. She felt terrific and parted her thighs wider. I smelled her young eager p**** aroma. It was intoxicating. You smell so fresh sweetie. My name is Lizzie. Call me Lizzie. As I messaged her thighs she respread hrr thighs. Am I all drippy? She asked. I moved my fingers to the edge of her vaginal flesh. Yes swee Lizz you are a little slippery. Met I touch your very soft p**** Lizz? Yes yes I ran my fingers over the slushy slit. From a** hole to her c*** I let my fingers fiddle and wiggle in between her inner and outer lips. Nearly virgin as she was the flesh was delicate and lovely. My fingers and c*** tingled as I played with her p****. She gasped a little. Oh oh oh press on my c******* Mr John. Rub it gently. It’s all on fire down there.what’s on fire? My hot p**** Mr John. I know Lizz but it will get much much hotter . I felt up between her inner lips and gently rubbing her buttonwatcher her face contorted as she bit met bottom lip. Ooooo ooooo. Ooooo she slobbered. Yes honey let it go let it grow wild up into your belly and spread. I will get much more exciting. Her 13 yr old p**** enraged my c*** snd it twitched maddeningly. I caressed the wet button slowly and drew circles around it then tapped it seversl times. Then pinched it and then pressed on it. Then gripped the tiny button. Oh oh oh I’m i’m ( I stopped all movements. She unstiffenefd her torso and nearly collapsed. No no no don’t stop. Just for a minute. Your climb up will be even better. Oh s*** oh s*** I have to peepee. Go ahead let it come. She let loose snd peed into a cup i ok held. I watched her urinate and nearly blew my wad. She finished. I wiped her puss and slid my finger to her wet c******* again. Yes yes yes as I rolled my finger over the now very tender c*** I lifted her Fanny closer to my chest. Now my hot breath covered her c***. But also bared her tiny button slowly and hole. It was pink and puckered. Tho delicious looking I chose to use my other finger to eiggle it over her sss hole. She jiggled her a** cheeks trying to tighten them, but I pulled them apart and slid my index finger up into her lovely little yielding hole as fsr as I could. Once fullly inserted I wiggled it round and round and round. She gagged a bit but I gently lifted the hood on her c*** and sucked it into my lips. My waiting tongue began licking her c*** faster and faster. She grunted. She cried out as her wave of lust built up. As I sucked harder she waved her arms skyward snd grabbed her n******, pinching hard. A wild scream may have begun, but no sound was emitting from her gasping mouth. Her a** rippled and bounced on my legs. She stiffened and then looking into my eyes she collapsed against my body. Gasping for oxygen she sagged into e***** exstacy. Oh god oh god. I hugged her tiny body warmly. Was it good for you Lizz? I asked.

Related Confessions