1

I am trying to update the content of an image from xcassets (through code, since I should download the new image) I need this so I can try to dynamically update the splash screen image and home page image (both are referenced from the same file in xcassets). This is because splash screen can only reference a locally present image.

I tried the following, but it does not work. Any help is appreciated.

    var urlString = Bundle.main.resourcePath
    
    let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
    let filename = URL(fileURLWithPath: urlString!)
    let fileURL = filename.appendingPathComponent("image_splashscreen@3x.png")
    if let pngImageData = image.pngData() {
    try! pngImageData.write(to: fileURL, options: .atomic)

And also:

    var documentsUrlw: URL {
        return FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
    }

    let fileName = "image_splashscreen@3x"
    let fileURL = documentsUrl.appendingPathComponent(fileName)
    if let imageData = image.jpegData(compressionQuality: 1.0) {
       try? imageData.write(to: fileURL, options: .atomic)
       return fileName // ----> Save fileName
    }

In both cases the image doesn't update.

  • I think Apple recommends that you don't add any splash text/randomized images in the launch screen. – aheze Jan 18 '21 at 18:58

1 Answers1

0

After seeing this question, I've searched a little bit for similar questions. For example this one: question

It says inside the Bundle(.xcassets resources) you cannot write any file to it. So you cannot write a file a URL even you have its documentation. So you have two options places when you saving/writing data: Caches / Documents.

eemrah
  • 1,603
  • 3
  • 19
  • 37