urbanairship / ios-library

Urban Airship iOS SDK
http://urbanairship.com
Apache License 2.0
478 stars 265 forks source link

Add AsyncSequences for events like channel created and channel updated as a convenience #398

Closed SwiftNativeDeveloper closed 5 months ago

SwiftNativeDeveloper commented 5 months ago

Preliminary Info

What Airship dependencies are you using?

18.0.x

What are the versions of any relevant development tools you are using?

Xcode 15.3

Report

What unexpected behavior are you seeing?

N/A Suggestion

What is the expected behavior?

It would be handy to have Airship expose some AsyncStreams or AsyncSequences around some of the notifications that are meant to be publicly listened to. I've recently looked at Apple provided sequences like the Transaction ones provided in StoreKit 2. I noticed in the migration guide from 17.x -> 18.x after finding some things renamed that the guide still references the legacy 'addObserver' functions on Notification Center.

While the SDK still is Swift 5.3 in the package it would be slick to just hook onto some sequences provided by you instead of having to know anything about the notifications being send via Notification Center under the hood.

You'd implement something like this: https://developer.apple.com/documentation/foundation/notificationcenter/3813137-notifications

And expose it as an async sequence like any of these:

What are the steps to reproduce the unexpected behavior?

N/A

Do you have logging for the issue?

N/A

SwiftNativeDeveloper commented 5 months ago

Reading one paragraph further in the migration guide and seeing the note about Channel Updated being removed, this would be a great candidate for AsyncSequence. So far my codebase doesn't use Combine directly and with this strategic change applied to AirshipNotificationStatus I could still avoid it! 😄

I'm guiding the teams I mentor to favor async await when possible especially in preparation for Swift 6.

crow commented 5 months ago

This is a good suggestion. We'll discuss it and keep you posted on what we decide to do.

rlepinski commented 5 months ago

Added in 18.1.0:

        Task {
            for await channelID in Airship.channel.identifierUpdates {
                print("Airship Channel ID: \(channelID)")
            }
        }

The update will always provide the current ID as the first element if available