BLACK FRIDAY: 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

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      

Save 50% in my WWDC sale.

SAVE 50% All our books and bundles are half price for Black Friday, 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!

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      

Save 50% in my WWDC sale.

SAVE 50% All our books and bundles are half price for Black Friday, 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!

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.