Save UIImage to PNG in App Bundle in Swift 3

612 Views Asked by At

With the new iOS 10.3 beta I heard that you can change the icon of your app programmatically using a PNG file included in your app and mentioning it in your Info.plist. I have successfully done this using images that were already in my app at build-time. My idea was that you could set the image to whatever you want, by getting a PNG representation of a UIImage and then saving it to a PNG file inside your app bundle, so that when the icon is changed it will be changed to that UIImage.

Let's say I have a PNG file (ic_custom.png) in my app here:

https://i.stack.imgur.com/eGsYm.jpg

How would I save a UIImage to this exact file (so that Info.plist could still read it), and could I access it using the setAlternateIcon method in Swift 3? If you can't write to it, then is there a way that the Info.plist could still access it if it were in the Documents directory?

0

There are 0 best solutions below