1

I'm making some maintenance on my iOS app with SwiftUI. One feature of this app is open the Files app (using fileimporter) to select a file, import it and make some analysis to it. This has been working ok so far.

But today I've suddenly found out that fileimporter it's not working properly and I'm pretty sure it was working ok some weeks ago and I haven't made any change in the app since then.

I'm thinking if it's a problem of any ios update.

My code to open fileimporter is this:

import SwiftUI

struct AnalyseFileView: View {
    
    @ObservedObject var observedModel: AnalyseFileViewAdapter
    
    @State var hasToOpenFilesApp = false
    @State var isViewVisible: Bool = false

    init(observedModel: AnalyseFileViewAdapter) {
        self.observedModel = observedModel
    }

    var body: some View {
        
        NavigationView {
            
            ZStack {
                
                VStack(alignment: .leading, spacing: 0) {
                    
                        ScrollView {
                            
                            VStack(alignment: .center, spacing: 0) {
                                
                                ...

                                CustomButton(title: "Open files app") {
                                    hasToOpenFilesApp = true
                                }.fileImporter(isPresented: $hasToOpenFilesApp, allowedContentTypes: [.text, .zip, .gzip, .vCard]) { result in
                                    switch result {
                                    case .success(let url):
                                        print(url)
                                        manageSelectedFile(url: url)
                                    case .failure(let error):
                                        print(error)
                                    }
                                }
                                .buttonStyle(CustomButtonStyle(style: .terciary, size: .large, isFullWidth: true))
                                .padding([.leading, .trailing], 25)
                                .padding(.bottom, 24)

                                ...
                                
                            }
                        }
                }
            }
            .background(Color("primary4_primary3"))
            .navigationBarHidden(true)
            .onAppear {
                isViewVisible = true
                startView()
            }
            .onAppCameToForeground {
                if isViewVisible {
                    startView()
                }
            }
            .onDisappear {
                isViewVisible = false
            }
        }
    }
    
    private func startView() {  
        observedModel.presenter?.viewWillAppear()
    }

    private func manageSelectedFile(url: URL) {
        
        observedModel.selectedFile = url
        guard url.startAccessingSecurityScopedResource() else { return }
        observedModel.presenter?.manageFilePicked(url: url)
        url.stopAccessingSecurityScopedResource()
    }
}

With my iPhones 16.5 and 16.2 Files app is open this way:

Files app

As you can see there is only the Recents option and there is no way to get the Browse button to go to iCloud, Dropbox, My Device, etc... Search bar is working, it finds my files in those locations but it's more friendly to have the browse button.

What could have happened? I'm pretty sure this browse button was being shown a couple of weeks ago.

Just in case, I've just tested in an iPhone 14 and iPhone 15 and Files app shows the correct button:

enter image description here

EDIT:

I've just made a very strange discovery:

If I open que Files app (without browse button) > I set a text in the Search bar > I clear the Search bar clicking the clear uitextfield button > I close the keyboard > the Files app shows its tabbar with the Recent, Shared and Browse tabs > I click on the Browse tab and Files app shows this:

enter image description here

It's like the browse section was disabled or I don't have permissions. What could have made this strange behavior?

EDIT 2:

I've made a little progress with this. It definitely seems a permissions problem:

If I make a fresh install from the app store of my app (file picker opened with UIDocumentPickerViewController) everything is OK > I update my new version (with this view in SwiftUI and file picker opened with fileimporter) and everything keeps working OK > I've tried a lot of things to reproduce the problem and if I've found out that if I revoke the File and folders permission of my app the incorrect behavior appears (files app is opened just with Recent items available).

So, my conclusion is:

The cause of my problem is that my app lost the files and folder permission. But how is this possible if I can guarantee that I have not revoked that permission manually?

And how could I check the status of this permission and request for it again?

Wonton
  • 1,033
  • 16
  • 33

0 Answers0