Friday, October 9, 2026
HomeiOS Developmentios - In swift, The right way to discover your entire URL...

ios – In swift, The right way to discover your entire URL of “Filepercent20Providerpercent20Storage”” as a way to ship to it a json file by code?

[ad_1]

I retrieve a URL adress solely after clicking a picture in a UIDocumentPickerViewController wich show at first “On my iphone” like within the photograph, by this fundamental operate:

func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
        guard let url = urls.first else {
            print("Il n'y a pas d'url qui provient de documentPicker")
                    return
                }
                        guard url.startAccessingSecurityScopedResource() else {
                            // Deal with the failure right here.
                            print("Guard a planté, url est vide")
                            return
                        }
                        do {
                            let urlTronque = url.deletingLastPathComponent()
                            print(url)
                            print("Do exécuté")
                        }
                        catch {
                            print(error.localizedDescription)
                            print("Catch avec erreur")
                        }
                        // Be sure you launch the security-scoped useful resource whenever you end.
                        do { url.stopAccessingSecurityScopedResource()
                            print("Defer exécuté")
                        }
            }

the print of the url retrieved had been:

file:///Customers/MyName/Library/Developer/CoreSimulator/Units/A9CA8F79-B11A-4EE3-985C-3062BD362CBE/knowledge/Containers/Shared/AppGroup/CDEE1F77-25D2-433F-9FB5-B516CC523A0E/Filepercent20Providerpercent20Storage/Imagepercent20JPE

Right here is the code of my button to go to UIDocumentPickerViewController:

@IBAction func ImportFile(_ sender: UIButton) {
       let supportedType: [UTType] = [UTType.json, UTType.image]
        let pickerViewController = UIDocumentPickerViewController(forOpeningContentTypes: supportedType, asCopy: false)
        pickerViewController.delegate = self
        pickerViewController.modalPresentationStyle = .overFullScreen
        pickerViewController.allowsMultipleSelection = false
        pickerViewController.shouldShowFileExtensions = true
        self.current(pickerViewController, animated: true, completion: nil)
        print("On est dans le file paperwork")     
        }

I search quite a bit, however i did not discover the code to save lots of a json file within the “file supplier storage”, I imply right here:
enter image description here

So at first, how can i do know your entire url of “Filepercent20Providerpercent20Storage” with out this advanced manipulation. my aim is to let the person of the app ship a json file to this adress.

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments