Asking for permissions with TCA (Updating UI without changing state)

Disclosure: Using UIKit not SwiftUI as the project is being rewritten. UI layer will be altered once business logic has been moved to TCA.

I have a case were I need to ask for Permissions for Camera, Reminders and Photo Library in various view controllers.

The checkForPermissions action is dispatched to request permission for a certain type, as detailed above.

enum PermissionsAction {
    case checkForPermissions(permissionType)
    case permissionStatus(Result<T, E>)
}

Which then uses an Effect in the reducer:

Effect<T, E>.future { callback in
    let authStatus = PHPhotoLibrary.authorizationStatus()
    switch authStatus {
    case .denied, .restricted:
        callback(.failure(.photos))
        
    case .notDetermined:
        PHPhotoLibrary.requestAuthorization { status in
            if status == .authorized {
                callback(.success(.photos))
            } else {
                callback(.failure(.photos))
            }
        }

    default:
        callback(.failure(.photos))
}

This is then mapped to another Effect, the permissionStatus action, to determine if there was an error or if the permission is granted. At which point the returned type of permission being requested is simply part of the Result output type.

Now the question:

I am currently using a piece of state that holds boolean values as to whether each type of permission has been granted. However, I want the ViewController to react each time the permission type authorisation status is returned. The failure case presents an alert, which is fine as I change a piece of state for this. However, in the success case I would rather tell the ViewController it's been granted so it can continue doing its work without having to manage state specifically.

Is there any way that I can send an action to the ViewController via the ViewStore, or something else like it. I want to trigger something in the ViewController without having to alter a piece of state :thinking:

Terms of Service

Privacy Policy

Cookie Policy