Vollan
Vollan

Reputation: 1915

Swift fileImporter size limiting

So i currently have this code:

.fileImporter(isPresented: .constant(true), allowedContentTypes: [.pdf]) { result in
        switch result {
        case .success(let url):
            if url.startAccessingSecurityScopedResource(), let pdf = try? NSData(contentsOfFile: url.path) as Data {
                 if !viewModel.validateFileSize(data: pdf) {
                      viewModel.attachments.append(.init(data: pdf))
                 }
             }
         case .failure:
            // some error handling
         }
}

The validation of file size works as it should etc. But what i want is the limit the user from the very beginning to not even be able to select files above certain file sizes. Can this be done? I can't seem to find anything when i search for it, and exploring the fileImporter functionality i can't seem to see something regarding size.

Upvotes: 2

Views: 455

Answers (0)

Related Questions