In some scenarios, we may need to get the app's icon name and the name of the startup image. For example, the app in the foreground, received a remote notification, but the notification bar will not have notification reminders, then I want to do a simulation notification prompt, need to use the icon name, and then when loading a controller, want to set the background picture of the controller as the boot image, you need to use the boot image name.
In fact, the icon image is placed in the System AppIcon folder, the boot image is placed in the System Launchimage folder, the name of these pictures and other general resource image name is different.
For the convenience of example, let's just be rude.
Suppose the current project supports only iphone devices and only supports vertical screens, and the AppIcon icon and boot image are already set up in the current project ,
How do I get the icon name and start picture name?
On the code and print logs:
/** Get the app icon name*/- (void) getappiconname{nsdictionary*infodict =[[NSBundle Mainbundle] infodictionary]; //get an array of all icon names in the appNsarray *iconsarr = infodict[@"cfbundleicons"][@"Cfbundleprimaryicon"][@"Cfbundleiconfiles"]; //take the name of the last iconNSString *iconlastname =[Iconsarr Lastobject]; //print icon NameNSLog (@"Iconsarr:%@", Iconsarr); NSLog (@"iconlastname:%@", Iconlastname); /*Print log: Iconsarr: (appicon29x29, appicon40x40, appicon60x60) Iconlastname:ap picon60x60*/}/** Get the app's startup picture name and set it as the background picture for this controller*/- (void) getlaunchimagename{NSString*launchimagename =@"";//start a picture name variableCGFloat screenheight =[UIScreen mainscreen].bounds.size.height; //gets the name of the boot picture that matches 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; //device boot picture for controller background pictureUIImage *img =[UIImage Imagenamed:launchimagename]; Self.view.backgroundColor=[Uicolor colorwithpatternimage:img]; //-----Print all the boot image information in the app-----Nsdictionary *infodict =[[NSBundle Mainbundle] infodictionary]; //get an array of all boot picture informationNsarray *launchimagesarr = infodict[@"uilaunchimages"]; NSLog (@"Launchimagesarr:%@", Launchimagesarr); /* Print log: The name of the boot 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}"; } )*/}
See, the Project AppIcon icon and start picture information can be obtained from [[nsbundle mainbundle] infodictionary] , Currently it also contains other information about the app such as version, app name, device type, support direction ...
Print all the information to see:
/** Print App engineering 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 = (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}"; } ); Uilaunchstoryboardname = Launchscreen; Uimainstoryboardfile = Main; Uirequireddevicecapabilities = (ARMV7); Uisupportedinterfaceorientations = (Uiinterfaceorientationportrait); }*/}
View Code
Original link: http://www.cnblogs.com/tandaxia/p/5820217.html
iOS get app icon and boot image name (AppIcon and Launchimage's name)