iOS gets AppIcon and Launchimage ' s name (app icon and startup picture name) _java

Source: Internet
Author: User

In some scenarios, maybe we need to get the name of the app icon and the startup picture. For example, when the app is in the foreground, received a remote notification but the notification bar will not have notification reminders, then I want to do a mock notification prompts, need to use icon name; For example, when you load a controller, you want to set the background picture of the controller to start the picture, you need to use the startup picture name.

In fact, the icon is placed in the System AppIcon folder, the startup picture is placed in the System Launchimage folder, the name of these pictures and other generic resources picture name is not the same.

For example, let's just be rough.

Suppose the current project supports only the iphone device, and only the vertical screen is supported, and the AppIcon icon and start picture are already set in the current project.

How do I get the icon name and start picture name?

On code and print log:

/** get the icon name of the app/-(void) getappiconname{nsdictionary *infodict = [[NSBundle mainbundle] infodictionary];/Get all of the apps
Icon Name array Nsarray *iconsarr = infodict[@ "Cfbundleicons"][@ "Cfbundleprimaryicon"][@ "Cfbundleiconfiles"];
Take the name of the last icon nsstring *iconlastname = [Iconsarr lastobject];
print icon name NSLog (@ "Iconsarr:%@", Iconsarr);
NSLog (@ "Iconlastname:%@", iconlastname); /* Print log: Iconsarr: (appicon29x29, appicon40x40, appicon60x60) iconlastname:appicon60x60/}/** get the name of the startup picture of the app and set it to the back of this controller View picture//(void) getlaunchimagename{nsstring *launchimagename = @ "";//Start picture name variable cgfloat screenheight = [UIScreen mainscreen
].bounds.size.height;  Gets the start picture name that matches the current device if (screenheight = =) {//4,4s Launchimagename = @ "LaunchImage-700";} else if (ScreenHeight = 568) {
5, 5C, 5S, IPod launchimagename = @ "launchimage-700-568h"; else if (screenheight = = 667) {//6, 6S launchimagename = @ "launchimage-800-667h";} else if (screenheight = = 736) {//6P LUs, 6SPlus launchimagename = @ "Launchimage-800-landsCAPE-736H ";
} if (Launchimagename.length < 1) return;
Device boot picture for controller background picture uiimage *img = [UIImage imagenamed:launchimagename]; 
Self.view.backgroundColor = [Uicolor colorwithpatternimage:img]; }

Print all startup picture information that is currently supported on only the iphone device and only supports vertical screen scenarios:

/** Print all startup picture name information in app/-(void) printalllaunchimageinfo{nsdictionary *infodict = [[NSBundle Mainbundle] Infodictionary
 ];
 Get all startup picture information array Nsarray *launchimagesarr = infodict[@ "Uilaunchimages"];
 NSLog (@ "Launchimagesarr:%@", Launchimagesarr);
  /* Print log: The name of the start picture 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 startup picture information can be obtained from [[NSBundle Mainbundle] infodictionary] , which also contains other information about the app such as version, app name, device type, 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); }
 */
}

----------then we'll come back to what AppIcon and launchimage are and how to get--- when apps support both the iphone and ipad devices and the horizontal and vertical screens .

First on the two map, then test the code:

Test code:

1, Get AppIcon all icon icons name

/** supports the iphone and ipad, and gets the icon name of the app * *
-(void) getappiconname{
 nsdictionary *infodict = [[NSBundle Mainbundle] Infodictionary];
 Get all icon names array
 nsarray *iconsarr = infodict[@ "Cfbundleicons"][@ "Cfbundleprimaryicon"][@ "Cfbundleiconfiles" in App "];
 Take the name of the last icon
 nsstring *iconlastname = [Iconsarr lastobject];
 Print icon name
 NSLog (@ "Iconsarr:%@", Iconsarr);
 NSLog (@ "Iconlastname:%@", iconlastname);
 /* Print log (29pt and 40pt iphone and ipad used; 60pt---iphone, 76pt and 83.5pt---ipad):
 Iconsarr: (
  appicon29x29,
  appicon40x40,
  appicon60x60,
  appicon76x76,
  "appicon83.5x83.5"
 )
 iconlastname:appicon83.5x83.5
 * *
}

2, access to support the iphone and ipad development, support horizontal and vertical screen, get the start picture, and set as background image code

(iphone device only in the plus, that is 5.5 inches only vertical screen and horizontal screen two sets of pictures, the other 4, 5, 6 vertical screen share a splash picture)

/** supports the iphone and ipad, supports the horizontal screen, the vertical screen, gets the app's startup picture name, and sets the controller background picture//(void) getlaunchimagename{nsstring *launchimagename = @ "" ; Start picture name variable cgfloat screenheight = [UIScreen mainscreen].bounds.size.height; Screen height cgfloat screenwidth = [UIScreen mainscreen].bounds.size.width;
 Screen width//device interface direction uiinterfaceorientation orientation = [UIApplication sharedapplication].statusbarorientation; BOOL isportrait = uiinterfaceorientationisportrait (orientation);//whether vertical screen bool Islandscape = Uiinterfaceorientationislandscape (orientation)//whether horizontal screen//Get the boot picture name that matches the current device//4, 4S vertical screen, horizontal screen if (isportrait && screenheight = 480) | | (islandscape && screenwidth = 480))
 {launchimagename = @ "LaunchImage-700"; ///5, 5 C, 5S, iPod vertical screen, crossbar else if ((isportrait && screenheight = 568) | | (islandscape && screenwidth = 568))
 {launchimagename = @ "launchimage-700-568h"; //6, 6S vertical, cross screen else if (isportrait && screenheight = 667) | | (islandscape && screenwidth = 667)) {LaunchImageName = @ "launchimage-800-667h"; }//6plus, 6SPlus, "else If" (isportrait && screenheight = = 736) {launchimagename = @ "launchimage-800-portrait-73
 6h "; //6plus, 6SPlus crossbar else if (islandscape && screenwidth = = 736) {launchimagename = @ "launchimage-800-landscape-
 736H ";
 //ipad the vertical screen else if (isportrait && screenheight = = 1024) {launchimagename = @ "launchimage-700-portrait";
 //ipad else if (islandscape && screenwidth = = 1024) {launchimagename = @ "Launchimage-700-landscape";
 } if (Launchimagename.length < 1) return;
 Device boot picture for controller background picture uiimage *img = [UIImage imagenamed:launchimagename];
Self.view.backgroundColor = [Uicolor colorwithpatternimage:img]; }

3, print out all startup picture Information

/** Print all startup picture name information in app/-(void) printalllaunchimageinfo{nsdictionary *infodict = [[NSBundle Mainbundle] Infodictionary
 ];
 Get all startup picture information array Nsarray *launchimagesarr = infodict[@ "Uilaunchimages"];
 NSLog (@ "Launchimagesarr:%@", Launchimagesarr);
  /* Print log: The name of the start picture 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, App
  icon60x60, 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 a small set to introduce the iOS get AppIcon and Launchimage ' s name (app icon and start picture name), I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.