In some scenario, we may need to get the app's icon name and the name of the startup image. For example, when the app is in the foreground, it receives a remote notification, but there will be no notification reminder in the notification bar. At this time, I want to make a simulated notification prompt, and I need to use the icon name; for example, when loading a certain controller, I want to set the background image of the controller as a startup image, and I need to use the startup image name.
In fact, the icon image is placed in the system AppIcon folder, and the startup image is placed in the system LaunchImage folder. The names of these images are different from those of other general resource images.
To give examples, let's be simple and rough.
Suppose the current project only supports iPhone devices and only supports vertical screens; and the AppIcon icon and startup image have been set in the current project.
How to get the icon icon name and the startup image name?
On the code and print the log:
/** Get the icon icon name of the app*/- (void)getAppIconName{NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];//Get all icon names in the app NSArray *iconsArr = infoDict[@"CFBundleIcons"][@"CFBundlePrimaryIcon"][@"CFBundleIconFiles"];//Get the last icon name NSString *iconLastName = [iconsArr lastObject];//Print the icon name NSLog(@"iconsArr: %@", iconsArr);NSLog(@"iconLastName: %@", iconLaunchName);/*Print log: iconsArr: (AppIcon29x29,AppIcon40x40,AppIcon60x60)iconLastName: AppIcon60x60*/}/** Get the name of the startup image of the app and set it to the background image of this controller*/- (void)getLaunchImageName{NSString *launchImageName = @""; //Start image name variable CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;//Get the startup image name matching the current device if (screenHeight == 480){ //4, 4SlaunchImageName = @"LaunchImage-700";}else if (screenHeight == 568){ //5, 5C, 5S, iPodlaunchImageName = @"LaunchImage-700-568h";}else if (screenHeight == 667){ //6, 6SlaunchImageName = @"LaunchImage-800-667h";}else if (screenHeight == 736){ // 6Plus, 6SPluslaunchImageName = @"LaunchImage-800-Landscape-736h";}if (launchImageName.length < 1) return;//The device startup image is the background image of the controller UIImage *img = [UIImage imageNamed:launchImageName]; self.view.backgroundColor = [UIColor colorWithPatternImage:img]; }Print all startup image information that currently supports only iPhone devices and only supports vertical screen scenes:
/** Print all startup image name information in the app*/- (void)printAllLaunchImageInfo{ NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary]; //Get all startup image information array NSArray *launchImagesArr = infoDict[@"UILaunchImages"]; NSLog(@"launchImagesArr: %@", launchImagesArr); /* Print log: The name of the startup image is fixed launchImagesArr: ( { UILaunchImageMinimumOSVersion = "8.0"; UILaunchImageName = "LaunchImage-800-Portrait-736h"; UILaunchImageOrientation = Portrait; UILaunchImageSize = "{414, 736}"; }, { UILaunchImageMinimumOSVersion = "8.0"; UILaunchImageName = "LaunchImage-800-Landscape-736h"; UILaunchImageOrientation = Landscape; UILaunchImageSize = "{414, 736}"; }, { UILaunchImageMinimumOSVersion = "8.0"; UILaunchImageName = "LaunchImage-800-667h"; UILaunchImageOrientation = Portrait; UILaunchImageSize = "{375, 667}"; }, { UILaunchImageMinimumOSVersion = "7.0"; UILaunchImageName = "LaunchImage-700"; UILaunchImageOrientation = Portrait; UILaunchImageSize = "{320, 480}"; }, { UILaunchImageMinimumOSVersion = "7.0"; UILaunchImageName = "LaunchImage-700-568h"; UILaunchImageOrientation = Portrait; UILaunchImageSize = "{320, 568}"; } ) */} I saw that the project AppIcon icon and startup image information can be obtained from [[NSBundle mainBundle] infoDictionary]. It also contains other information about the app, such as version, app name, device type, and support direction. . .
Print all the information to see:
/** Print app project configuration information*/- (void)printInfoDictionary{ NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary]; NSLog(@"%@", infoDict); /* Print log: { BuildMachineOSBuild = 15G31; CFBundleDevelopmentRegion = en; CFBundleExecutable = TanTest; CFBundleIcons = { CFBundlePrimaryIcon = { CFBundleIconFiles = ( AppIcon29x29, AppIcon40x40, AppIcon60x60 ); }; }; CFBundleIdentifier = "net.tan.xxx"; CFBundleInfoDictionaryVersion = "6.0"; CFBundleInfoPlistURL = "Info.plist -- file:///Users/PX/Library/Developer/CoreSimulator/Devices/7020368B-C160-42C0-B3C5-5F958FA82EF5/data/Containers/Bundle/Application/77D8C333-A6AF-4183-B79A-A5BEDCD08E1A/TanTest.app/"; CFBundleName = TanTest; CFBundleNumericVersion = 16809984; CFBundlePackageType = APPL; CFBundleShortVersionString = "1.0"; CFBundleSignature = "????"; CFBundleSupportedPlatforms = (iPhoneSimulator); CFBundleVersion = 1; DTCompiler = "com.apple.compilers.llvm.clang.1_0"; DTPlatformBuild = ""; DTPlatformName = iPhonesimulator; DTPlatformVersion = "9.3"; DTSDKBuild = 13E230; DTSDKName = "iphonesimulator9.3"; DTXcode = 0731; DTXcodeBuild = 7D1014; LSRequiresIPhoneOS = 1; MinimumOSVersion = "6.0"; UIDeviceFamily = ( ); UILaunchImageFile = LaunchImage; UILaunchImages = ( { UILaunchImageMinimumOSVersion = "8.0"; UILaunchImageName = "LaunchImage-800-Portrait-736h"; UILaunchImageOrientation = Portrait; UILaunchImageSize = "{414, 736}"; }, { UILaunchImageMinimumOSVersion = "8.0"; UILaunchImageName = "LaunchImage-800-Landscape-736h"; UILaunchImageOrientation = Landscape; UILaunchImageSize = "{414, 736}"; }, { UILaunchImageMinimumOSVersion = "8.0"; UILaunchImageName = "LaunchImage-800-667h"; UILaunchImageOrientation = Portrait; UILaunchImageSize = "{375, 667}"; }, { UILaunchImageMinimumOSVersion = "7.0"; UILaunchImageName = "LaunchImage-700"; UILaunchImageOrientation = Portrait; UILaunchImageSize = "{320, 480}"; }, { UILaunchImageMinimumOSVersion = "7.0"; UILaunchImageName = "LaunchImage-700-568h"; UILaunchImageOrientation = Portrait; UILaunchImageSize = "{320, 568}"; } ); UILaunchStoryboardName = LaunchScreen; UIMainStoryboardFile = Main; UIRequiredDeviceCapabilities = ( armv7 ); UISupportedInterfaceOrientations = ( UIInterfaceOrientationPortrait ); } */} --------- Next, let's look at how AppIcon and LaunchImage are like and how to obtain when the app supports both iPhone and iPad devices, as well as horizontal and vertical screens.
First, add two pictures, and then add the test code:
Test code:
1. Get all icon icon names of AppIcon
/** Support iPhone and iPad, get the icon icon name of the app */- (void)getAppIconName{ NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary]; //Get all icon names in the app NSArray *iconsArr = infoDict[@"CFBundleIcons"][@"CFBundlePrimaryIcon"][@"CFBundleIconFiles"]; //Get the last icon name NSString *iconLastName = [iconsArr lastObject]; //Print the icon name NSLog(@"iconsArr: %@", iconsArr); NSLog(@"iconLastName: %@", iconLastName); /* Print logs (29pt and 40pt iPhone and iPad are used; 60pt --- iPhone, 76pt and 83.5pt --- iPad): iconsArr: (AppIcon29x29, AppIcon40x40, AppIcon60x60, AppIcon76x76, "AppIcon83.5x83.5" ) iconLastName: AppIcon83.5x83.5 */} 2. Get the startup picture when supporting iPhone and iPad development, and supports horizontal and vertical screens, and set it as background picture code.
(The iPhone device only has two sets of pictures on Plus, that is, 5.5 inches, and the other 4, 5, and 6 vertical screens share a startup picture)
/** Support iPhone and iPad, support horizontal and vertical screens, get the name of the startup image of the app and set it to the background image of this controller*/- (void)getLaunchImageName{ NSString *launchImageName = @""; //Start image name variable CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height; //Screen height CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width; //Screen width//Device interface orientation UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; BOOL isPortrait = UIInterfaceOrientationIsPortrait(orientation);// Whether to have a vertical screen BOOL isLandscape = UIInterfaceOrientationIsLandscape(orientation);//Where to have a horizontal screen//Get the startup image name that matches the current device//4, 4S vertical screen, horizontal screen if ((isPortrait && screenHeight == 480) || (isLandscape && screenWidth == 480)){ launchImageName = @"LaunchImage-700"; } //5, 5C, 5S, iPod vertical screen, horizontal screen else if ((isPortrait && screenHeight == 568) || (isLandscape && screenWidth == 568)){ launchImageName = @"LaunchImage-700-568h"; } //6, 6S vertical screen, horizontal screen else if ((isPortrait && screenHeight == 667) || (isLandscape && screenWidth == 667)){ launchImageName = @"LaunchImage-800-667h"; } //6Plus, 6SPlus vertical screen else if (isPortrait && screenHeight == 736){ launchImageName = @"LaunchImage-800-Portrait-736h"; } //6Plus, 6SPlus horizontal screen else if (isLandscape && screenWidth == 736){ launchImageName = @"LaunchImage-800-Landscape-736h"; } //iPad vertical screen else if (isPortrait && screenHeight == 1024){ launchImageName = @"LaunchImage-700-Portrait"; } //iPad horizontal screen else if (isLandscape && screenWidth == 1024){ launchImageName = @"LaunchImage-700-Landscape"; } if (launchImageName.length < 1) return; //The device startup image is the background image of the controller UIImage *img = [UIImage imageNamed:launchImageName]; self.view.backgroundColor = [UIColor colorWithPatternImage:img];}3. Print out all startup image information
/** Print all startup image name information in the app*/- (void)printAllLaunchImageInfo{ NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary]; //Get all startup image information array NSArray *launchImagesArr = infoDict[@"UILaunchImages"]; NSLog(@"launchImagesArr: %@", launchImagesArr); /* Print log: The name of the startup image is fixed launchImagesArr: ( { UILaunchImageMinimumOSVersion = "8.0"; UILaunchImageName = "LaunchImage-800-Portrait-736h"; UILaunchImageOrientation = Portrait; UILaunchImageSize = "{414, 736}"; }, { UILaunchImageMinimumOSVersion = "8.0"; UILaunchImageName = "LaunchImage-800-Landscape-736h"; UILaunchImageOrientation = Landscape; UILaunchImageSize = "{414, 736}"; }, { UILaunchImageMinimumOSVersion = "8.0"; UILaunchImageName = "LaunchImage-800-667h"; UILaunchImageOrientation = Portrait; UILaunchImageSize = "{375, 667}"; }, { UILaunchImageMinimumOSVersion = "7.0"; UILaunchImageName = "LaunchImage-700"; UILaunchImageOrientation = Portrait; UILaunchImageSize = "{320, 480}"; }, { UILaunchImageMinimumOSVersion = "7.0"; UILaunchImageName = "LaunchImage-700-568h"; UILaunchImageOrientation = Portrait; UILaunchImageSize = "{320, 568}"; }, { UILaunchImageMinimumOSVersion = "7.0"; UILaunchImageName = "LaunchImage-700-Portrait"; UILaunchImageOrientation = Portrait; UILaunchImageSize = "{768, 1024}"; }, { UILaunchImageMinimumOSVersion = "7.0"; UILaunchImageName = "LaunchImage-700-Landscape"; UILaunchImageOrientation = Landscape; UILaunchImageSize = "{768, 1024}"; } ) */} 4. Print all configuration information
/** Print app project configuration information*/- (void)printInfoDictionary{ NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary]; NSLog(@"%@", infoDict); /* Print log: { BuildMachineOSBuild = 15G31; CFBundleDevelopmentRegion = en; CFBundleExecutable = TanTest; CFBundleIcons = { CFBundlePrimaryIcon = { CFBundleIconFiles = ( AppIcon29x29, AppIcon40x40, AppIcon60x60, AppIcon76x76, "AppIcon83.5x83.5" ); }; }; CFBundleIdentifier = "net.tan.xxx"; CFBundleInfoDictionaryVersion = "6.0"; CFBundleInfoPlistURL = "Info.plist -- file:///Users/PX/Library/Developer/CoreSimulator/Devices/3246F9AE-1D73-4E4F-8DDF-F591DBE64F63/data/Containers/Bundle/Application/7DD6C793-F882-43CF-9897-1433411289E6/TanTest.app/"; CFBundleName = TanTest; CFBundleNumericVersion = 16809984; CFBundlePackageType = APPL; CFBundleShortVersionString = "1.0"; CFBundleSignature = "????"; CFBundleSupportedPlatforms = (iPhoneSimulator); CFBundleVersion = 1; DTCompiler = "com.apple.compilers.llvm.clang.1_0"; DTPlatformBuild = ""; DTPlatformName = iPhonesimulator; DTPlatformVersion = "9.3"; DTSDKBuild = 13E230; DTSDKName = "iphonesimulator9.3"; DTXcode = 0731; DTXcodeBuild = 7D1014; LSRequiresIPhoneOS = 1; MinimumOSVersion = "9.0"; UIDeviceFamily = ( 1, ); UILaunchImageFile = LaunchImage; UILaunchImages = ( { UILaunchImageMinimumOSVersion = "8.0"; UILaunchImageName = "LaunchImage-800-Portrait-736h"; UILaunchImageOrientation = Portrait; UILaunchImageSize = "{414, 736}"; }, { UILaunchImageMinimumOSVersion = "8.0"; UILaunchImageName = "LaunchImage-800-Landscape-736h"; UILaunchImageOrientation = Landscape; UILaunchImageSize = "{414, 736}"; }, { UILaunchImageMinimumOSVersion = "8.0"; UILaunchImageName = "LaunchImage-800-667h"; UILaunchImageOrientation = Portrait; UILaunchImageSize = "{375, 667}"; }, { UILaunchImageMinimumOSVersion = "7.0"; UILaunchImageName = "LaunchImage-700"; UILaunchImageOrientation = Portrait; UILaunchImageSize = "{320, 480}"; }, { UILaunchImageMinimumOSVersion = "7.0"; UILaunchImageName = "LaunchImage-700-568h"; UILaunchImageOrientation = Portrait; UILaunchImageSize = "{320, 568}"; }, { UILaunchImageMinimumOSVersion = "7.0"; UILaunchImageName = "LaunchImage-700-Portrait"; UILaunchImageOrientation = Portrait; UILaunchImageSize = "{768, 1024}"; }, { UILaunchImageMinimumOSVersion = "7.0"; UILaunchImageName = "LaunchImage-700-Landscape"; UILaunchImageOrientation = Landscape; UILaunchImageSize = "{768, 1024}"; } ); UILaunchStoryboardName = LaunchScreen; UIMainStoryboardFile = Main; UIRequiredDeviceCapabilities = ( armv7 ); UISupportedInterfaceOrientations = ( UIInterfaceOrientationPortrait, UIInterfaceOrientationLandscapeLeft, UIInterfaceOrientationLandscapeRight ); }*/}The above is the iOS AppIcon and LaunchImage's name (app icon and launch image name) introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support to Wulin.com website!