iOS notification handling is kinda cray
As of iOS 9, these are the methods a UIApplicationDelegate
has to implement to handle all the different notification types iOS might throw at an app.
// Sent to the delegate when a running app receives a local notification.
application(_:didReceiveLocalNotification:)
// Called when your app has been activated because user selected
// a custom action from the alert panel of a local notification.
application(_:handleActionWithIdentifier:
forLocalNotification:
completionHandler:)
// (New in iOS 9.0) Called when your app has been activated
// by the user selecting an action from a local notification.
application(_:handleActionWithIdentifier:
forLocalNotification:
withResponseInfo:
completionHandler:)
// Called when your app has received a remote notification.
application(_:didReceiveRemoteNotification:)
// Called when your app has received a remote notification.
application(_:didReceiveRemoteNotification:
fetchCompletionHandler:)
// Tells the app delegate to perform the
// custom action specified by a remote notification.
application(_:handleActionWithIdentifier:
forRemoteNotification:
completionHandler:)
// (New in iOS 9.0) Tells the app delegate to
// perform the custom action specified by a remote notification.
application(_:handleActionWithIdentifier:
forRemoteNotification:
withResponseInfo:completionHandler:)
That’s a lot of very similar APIs! Additionally, there are keys for application(_: didFinishLaunchingWithOptions:)
that ALSO pass in notifications (RemoteNotificationKey
, LocalNotificationKey
). By my count that makes 9 different places to handle notifications. The ins and outs of which method is going to be called for any given interaction is a flow chart that would take up a whiteboard.
In an app with a robust notification scheme, missing any of these can cause head-scratching bugs.
Here's my proposal...
Unify remote notifications and UILocalNotification
notifications under a single UINotification
superclass. Make all the delegate methods handle the superclass and the delegate can cast to local/remote as needed. Boom. Half the methods. A UIRemoteNotification
class would be super useful too, it’s still a Dictionary
for Pete’s sake!