Home > Mobile >  Best way to notify framework clients of state changes on iOS
Best way to notify framework clients of state changes on iOS

Time:03-18

I'm developing a framework for iOS apps that allows interfacing with custom BLE devices made by my company. We're planning to distribute the framework binary with public headers to clients. I've already designed the client facing interface, but it's lacking a major feature: notification on various different status conditions. That is, when the framework starts scanning for devices, connects to a device, reads data, uploads to our backend, etc, there is currently no way for client apps to know.

This has been fine for local testing, but before releasing, it would be best to add some functionality to allow clients to build a UI that updates based on these various status conditions. I'm not entirely sure of what the current, best way to do this is. I'm aware I can create an NSNotificationCenter and post notifications for each of these status changes, but I'm not sure if there is some better way of doing this? Should I accept a user callback? Expose some sort of listener protocol and ability register listeners? I'm sure others have solved this problem before, what have you found works well for iOS?

CodePudding user response:

Use NSNotificationCenter for one to many communication, it notifies all the objects, which register to event, without knowing who throws it.

Use protocol and delegates for one to one object communication.

As per my experience you should go with delegates, it will be clean implementation and you can also define optional and required protocol.The the global class on client side can use this delegates, and update.

  • Related