Matthew Burke's answer is the correct answer. Below is the code I'm using to get this working for iOS9 / Xcode7, building an app for iOS7 and up, for iPhone and iPad, landscape allowed.
First, to elaborate a bit more:
In iOS8 / Xcode6, if you were using a storyboard Launch Screen File, on app startup, the app would create 2 images (one portrait, one landscape) of that launch screen file in the correct resolution for your device and you were able to get that image from the file path. (I believe it was stored in Library/LaunchImage folder).
However in iOS9/XCode 7 this image is not created anymore (although a snapshot is taken in the snapshots folder, but that has a undescriptive name that changes all the time), so if you want to use your LaunchImage somewhere else in your code, you'll have to use a Launch Image Source (through asset catalog preferably, because of App Thinning). Now, as Matthew Burke is explaining you can't get to that image just by doing:
let launchImage = UIImage(named: "LaunchImage")
Even though the image name in your asset catalog is LaunchImage, Xcode/iOS9 won't let you.
Luckily you don't have to include your launch images again in your asset catalog. I'm saying luckily because that would mean about a 20MB increase of your App Download size if you're making an app for all devices.
So, how to get to those launch images than? Well, here are the steps:
- Create your launch images and put them in your asset catalog. Name of the images is not important.
- Make sure your Launch Screen File (under your target's general settings) is empty and remove your app from your device and simulator. (just deleting the filename and re-running won't do it, you'll have to remove your app first)
- Run your app in the simulator and go to the ~/Library/Application Support/iPhone Simulator folder and find your app there. (It's a bit of a hassle as the folder names are indescriptive.) Show the package content for your .app file and in there you'll see several image files starting with "LaunchImage- ..." In my case there were 9 images as I'm making an app for iPhone and iPad for iOS7 and up.
Then, in your code you'll need to determine what device your app is running on and if it's in portrait or landscape and then decide which image to use. To make this a bit easier I used this framework: https://github.com/InderKumarRathore/DeviceGuru . Be ware, it didn't include the latest devices yet (iPhone 6s and iPhone 6s plus) so you'll have to add a line in his swift file for that. Then, put below piece of code in the vc where you want your launchImage and there you go:
func launchImage() -> UIImage? {
if let launchImageName = launcheImageName() {
print(launchImageName)
return UIImage(named: launchImageName)
}
else {
print("no launch image")
return nil
}
}
func launcheImageName() -> String? {
let HD35 = "LaunchImage-700@2x.png"
let HD40 = "LaunchImage-700-568h@2x"
let HD47 = "LaunchImage-800-667h@2x.png"
var HD55 = "LaunchImage-800-Portrait-736h@3x.png"
var padHD = "LaunchImage-700-Portrait@2x~ipad.png"
var pad = "LaunchImage-700-Portrait~ipad.png"
if UIDevice.currentDevice().orientation == UIDeviceOrientation.LandscapeLeft || UIDevice.currentDevice().orientation == UIDeviceOrientation.LandscapeRight {
HD55 = "LaunchImage-800-Landscape-736h@3x.png"
padHD = "LaunchImage-700-Landscape@2x~ipad.png"
pad = "LaunchImage-700-Landscape~ipad.png"
}
let hardware = hardwareString()
if (hardware == "iPhone1,1") { return HD35 }
if (hardware == "iPhone1,2") { return HD35 }
if (hardware == "iPhone2,1") { return HD35 }
if (hardware == "iPhone3,1") { return HD35 }
if (hardware == "iPhone3,2") { return HD35 }
if (hardware == "iPhone3,3") { return HD35 }
if (hardware == "iPhone4,1") { return HD35 }
if (hardware == "iPhone5,1") { return HD40 }
if (hardware == "iPhone5,2") { return HD40 }
if (hardware == "iPhone5,3") { return HD40 }
if (hardware == "iPhone5,4") { return HD40 }
if (hardware == "iPhone6,1") { return HD40 }
if (hardware == "iPhone6,2") { return HD40 }
if (hardware == "iPhone7,1") { return HD55 }
if (hardware == "iPhone7,2") { return HD47 }
if (hardware == "iPhone8,1") { return HD55 }
if (hardware == "iPhone8,2") { return HD47 }
if (hardware == "iPod1,1") { return HD35 }
if (hardware == "iPod2,1") { return HD35 }
if (hardware == "iPod3,1") { return HD35 }
if (hardware == "iPod4,1") { return HD35 }
if (hardware == "iPod5,1") { return HD40 }
if (hardware == "iPad1,1") { return pad }
if (hardware == "iPad1,2") { return pad }
if (hardware == "iPad2,1") { return pad }
if (hardware == "iPad2,2") { return pad }
if (hardware == "iPad2,3") { return pad }
if (hardware == "iPad2,4") { return pad }
if (hardware == "iPad2,5") { return pad }
if (hardware == "iPad2,6") { return pad }
if (hardware == "iPad2,7") { return pad }
if (hardware == "iPad3,1") { return padHD }
if (hardware == "iPad3,2") { return padHD }
if (hardware == "iPad3,3") { return padHD }
if (hardware == "iPad3,4") { return padHD }
if (hardware == "iPad3,5") { return padHD }
if (hardware == "iPad3,6") { return padHD }
if (hardware == "iPad4,1") { return padHD }
if (hardware == "iPad4,2") { return padHD }
if (hardware == "iPad4,3") { return padHD }
if (hardware == "iPad4,4") { return padHD }
if (hardware == "iPad4,5") { return padHD }
if (hardware == "iPad4,6") { return padHD }
if (hardware == "iPad4,7") { return padHD }
if (hardware == "iPad4,8") { return padHD }
if (hardware == "iPad5,3") { return padHD }
if (hardware == "iPad5,4") { return padHD }
if (hardware == "i386") { return HD55 }
if (hardware == "x86_64") { return HD55 }
if (hardware.hasPrefix("iPhone")) { return HD55 }
if (hardware.hasPrefix("iPod")) { return HD55 }
if (hardware.hasPrefix("iPad")) { return padHD }
//log message that your device is not present in the list
logMessage(hardware)
return nil
}