UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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

3      

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

3      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

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:

3      

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.

3      

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

3      

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

3      

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.

3      

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

3      

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

3      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

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

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

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.