WWDC22 SALE: Save 50% on all my Swift books and bundles! >>

Handle receiving of push notifications

Forums > iOS

Good morning

Haven't found any reference here to an example how to extend an existing iOS app to be able to receive push notifications... Just now that an AppDelegate.swift file is involved (o;

Interesting that push notifications is not handled in any of the four iOS books...or I am totally blind this morning (o;

thanks in advance richard

   

Read through the Ray Wenderlich intro as well...and still wondering where AppDelegate.swift is coming from:

Open AppDelegate.swift and add the following to the top of the file:

From the description it isn't just an empty file to be created but needs to be already there...

   

Hacking with Swift is sponsored by Emerge

SPONSORED Why are Swift reference types bad for app startup time, and what’s the performance cost of protocol conformances? That’s just a couple of the topics you can learn about on the Emerge blog — written by the app performance experts behind Emerge’s advanced app optimization and monitoring tools, based on their experience of working at companies like Apple, Airbnb, Snap, and Spotify.

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Looks this one is the best documentation for erceiving push notifications as it explains how to use the AppDelegate adapter:

   

Recently completed a SwiftUI based iOS application (now in TestFlight) using Firebase realtime database including push notifications. The code indeed looks very similar to that of the above mentioned examples, however, the most difficult part was to implement Firebase push notifications on database updates. Happy to share some details if you wish.

   

Thanks for the generous offer....just great community here :-)

But...it already works with my Debian Server...yessss :-)

Trick was to get the deviceToken Hex String from my iPhone.....

Now how do I get rid of the icon badge now (o; Sure a function is missing in my AppDelegate.....

   

Ah simple...just don't send a badge...:

payload = Payload(alert="New order received from\nRichard Klingler", sound="default", badge=0)

But still would be good to know how to jump into a specific view and clear the icon badge....

Like to open the right tab view and jump into the detail view of the order....

   

From the description it isn't just an empty file to be created but needs to be already there...

My guess is it is in the downloaded materials for this tutorial. The tutorial was created for Xcode 12 and iOS 14. Also, this was updated from an even older iOS version. Just for information. There is a complete book about Push Notifications: https://www.raywenderlich.com/books/push-notifications-by-tutorials But it's not free and not yet updated for iOS 15, unfortunately.

   

Clearing the badge icon is best done when the user activates the main application view.

    .onChange(of: scenePhase) {newPhase in
        if newPhase == .active {
            UIApplication.shared.applicationIconBadgeNumber = 0

   

What pops into my mind...

I use the AppDelegate adaptor to register the device token on my server for delivering the notifications...

But how do people handle:

  • User deletes the app from its iPhone
  • User reverts his iPhone to factory settings

Can those two cases also be handled somehow so that the registred tokens are removed as well?

thanks in advance richard

   

Hacking with Swift is sponsored by Emerge

SPONSORED Optimize your app’s startup time, binary size, and overall performance using Emerge’s advanced app optimization and monitoring tools. Reliably measure app size, speed up your app's startup time with Emerge's Launch Booster, and much more. Emerge is actively used by many of the top mobile development teams in the world.

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.