Push Notifications Tutorial: Getting Started | raywenderlich.com

Based on the document, when silent push notification comes in, the app will be waked up. Does this mean the application will be launched automatically if the app was killed or not running?

As described at the end of this page https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/HandlingRemoteNotifications.html, your AppDelegate will receive the push notification payload even if not running or in the background. If the user taps on the notification, you can bring your app to the foreground and do other things, as shown in the tutorial.

I was following along with the tutorials for the push notifications and am currently stuck on the simulated push notification section of the tutorial.

I ran this command on terminal:

xcrun simctl push F520D499-2428-4C1E-A3B3-CEBF01F839DE com.appworkshop.GotNext first.apn

and this error message shows up despite having created the first.apn file:

The file “first.apn” couldn’t be opened because there is no such file.
The file doesn’t exist.
Underlying error (domain=NSPOSIXErrorDomain, code=2):
The operation couldn’t be completed. No such file or directory
No such file or directory

Be sure you are in the directory where the first.apn file is located or else give the full path to the file.

HI, I get no token at all, I was following the tutorial, using Xcode 12.3, running the “didFailToRegisterForRemoteNotificationsWithError” method, I get Failed to register: Error Domain=NSCocoaErrorDomain Code=3010 “remote notifications are not supported in the simulator” UserInfo={NSLocalizedDescription=remote notifications are not supported in the simulator} but you said this issue should be not present on latest Xcode. on my developer account, I see notification activated for the app, but requires to configure certificates Development SSL Certificate and Production SSL Certificate but you did not mentioned them. am I wrong, or Apple changed simulator usage again? additionallly printing settings I get Notification settings: <UNNotificationSettings: 0x6000009b1f80; authorizationStatus: Authorized, notificationCenterSetting: Enabled, soundSetting: Enabled, badgeSetting: Enabled, lockScreenSetting: Enabled, carPlaySetting: NotSupported, announcementSetting: NotSupported, criticalAlertSetting: NotSupported, alertSetting: Enabled, alertStyle: Banner, groupingSetting: Default providesAppNotificationSettings: No>

@biggreentree I just now ran the app in Xcode 12.3 and it worked fine for me. I show zero certificates for the app in my Apple Developer account, like you. Not sure what is causing this issue on your system. Have you tried this with the “finished” app from the downloads?

Hi, thanks for your answer, yes, I tried the “final” one, changing only the bundle id into the one I created for the starter project, same message, and no token. I removed apps from simulator same result.

I wish I could do more to troubleshoot the issue you are having. If you are able to run on a real device, there are instructions to do so near the end of the tutorial.

thank you anyway. For now I can tell you that even If I still have the “failed” message on the simulator, I can send notification to it via the console string you use, but you should correct such string, the file should be .apns as in your picture not .apn, and should be explained that when in terminal, the line should be using the path to the file (at least, this way worked for me) not the name of the file xcrun simctl push your_device_id your_bundle_id PATH_TO_first.apns. If I’m missing something please tell me :smiley: (is there a place where such file should be put?). Later I’ll try to send to real device as you say. UPDATE is it necessary to install the utility for sending notifications to real device in order to have silent notifications working? I put a breakpoint right before the guard statement in didReceiveRemoteNotification but is never called

Thank you for your suggestions. I made an edit which I hope will clarify things. Readers like you help us improve our content.

in one of the first steps of this tutorial. when we are supposed to add a capability “push notifications” you should mention that the “automatically menage signing” box needs to be unchecked. It took me ages to figure out how to add push notifications because it doesn’t appear at all while “automatically menage signing” box is checked and it is checked by default.

@slobagamer That option should appear whether or not automatically manage signing is checked. The two things are not connected. To verify, I just now created a brand new project, selected the Signing & Capabilities tab, clicked on the + symbol and was able to add the push notifications capability.

I couldn’t see it until I unchecked the box. And I’m pretty sure I changed nothing else.

also using @UIApplicationMain is now officially deprecated, from what I gather so it is a bit difficult to follow again one of the first steps because when I make a new project I don’t have

@UIApplicationMain

class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application()

instead I have

@main
struct SiuvsMobileApp: App {
var body: some Scene {
WindowGroup {}
}

as a complete noob in swiftUI but an experienced programmer I use tutorials like this to implement push notifications directly in the project I’m working on rather than practising on the supplied materials precisely because some things are different. But I was hoping that since the article is updated it would be possible to follow all the steps easily.
I am now developing an iOS app that is same as android app I made a few months ago. I was following raywenderlich android push notifications tutorial and got it working without any differences compared to the android tutorial. Right now I have to google where to put the "func registerForPushNotifications() " which is something I was hoping I wouldn’t have to do.

Im just saying all this because I was amazed with how good the android push notifications tutorial was so I figure you might want to update this one once again.

@slobagamer First, I’m sorry that this tutorial has not been as helpful to you. This is marked as an intermediate level article and assumes a certain level of familiarity with iOS development, which may be a factor.

As for your comments about @UIApplicationMain, it is not deprecated. In fact, it was only introduced with iOS 12. See Apple’s documentation on @UIApplicationMain.. However, as you have probably read, SwiftUI is the new way of creating UIs in iOS. However, both UIKit and SwiftUI are supported and likely will be for a very long time. UIKit is a long way from being deprecated. My own products use UIKit extensively, as do many others, and will likely continue to use UIKit for a long time.

Great tutorial.
Small suggestion - please mention background modes in section “Working With Actionable Notifications”. The Background modes are mentioned in further chapters, but during the work according to tutorial flow the example “Pull down the notification and tap the View action, and you’ll see WenderCast present a Safari View controller right after it launches” with usage of UNUserNotificationCenter.current().delegate = self without background modes is not working (on iOS14 Simulator) and generates error:

“”" WenderCast[5381:521866] You’ve implemented -[ application:didReceiveRemoteNotification:fetchCompletionHandler:], but you still need to add “remote-notification” to the list of your supported UIBackgroundModes in your Info.plist. “”"

I will investigate this over the weekend and follow up with you.

@superuser I reran the tutorial up through the end of the “Working With Actionable Notifications” section and could not reproduce the error you are seeing. I started with the starter project and made all the changes directed in the tutorial and did not see the error about background modes because up to that point, those had not be implemented in the tutorial. If I start with the finished project, then the error occurs. Is it possible you had already implemented the background modes and returned to this section when you saw the error?

Thank you for this outstanding tutorial i learned a-lot but get a " Invalid device:"

I have check in the windows>devices tried it with several different devices to no avail.

Thinking it was a wrong placement program blocks in the swift file so I cut and pasted from your final version still no.

Edit: Found this error . running xcode 12.5 on Big Surf

No news file exists yet.

Permission granted: true

Notification settings: <UNNotificationSettings: 0x6000023f99d0; authorizationStatus: Authorized, notificationCenterSetting: Enabled, soundSetting: Enabled, badgeSetting: Enabled, lockScreenSetting: Enabled, carPlaySetting: NotSupported, announcementSetting: NotSupported, criticalAlertSetting: NotSupported, alertSetting: Enabled, alertStyle: Banner, groupingSetting: Default providesAppNotificationSettings: No>

Failed to register: Error Domain=NSCocoaErrorDomain Code=3010 “remote notifications are not supported in the simulator” UserInfo={NSLocalizedDescription=remote notifications are not supported in the simulator}

I would be happy to help, but need more information. At what specific point in the tutorial did you get this error? The error message appears to show that you attempted to send a real remote notification to the simulator, which is not supported. What is supported is the command line method using simctl described in the tutorial.

If you only have 1 simulator booted, you can use this command:

xcrun simctl push booted com.kingdesignapps.pushtestap first.apn