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

   

Save 50% in my Black Friday sale.

SAVE 50% To celebrate WWDC22, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

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

   

Save 50% in my Black Friday sale.

SAVE 50% To celebrate WWDC22, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

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.