iOS获取AppIcon and LaunchImage's name(app图标和启动图片名字)

在某种场景下,可能我们需要获取app的图标名称和启动图片的名称。比如说app在前台时,收到了远程通知但是通知栏是不会有通知提醒的,这时我想做个模拟通知提示,需要用到icon名称;再比如在加载某个控制器时,想设置该控制器的背景图片为启动图片,需要用到启动图片名称。

  而事实上icon图片放在系统AppIcon文件夹里,启动图片放在系统LaunchImage文件夹里,取这些图片的名称和其他一般资源图片名称不一样。

  为了方便举例子,咱们先简单粗暴点

假设当前项目只支持iPhone设备,并且只支持竖屏;而且当前项目里已经设置好了AppIcon图标和启动图片,

如何获取icon图标名称和启动图片名称呢 ?

上代码和打印日志:

/** 获取app的icon图标名称 */
- (void)getAppIconName{
NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
//获取app中所有icon名字数组
NSArray *iconsArr = infoDict[@"CFBundleIcons"][@"CFBundlePrimaryIcon"][@"CFBundleIconFiles"];
//取最后一个icon的名字
NSString *iconLastName = [iconsArr lastObject];
//打印icon名字
NSLog(@"iconsArr: %@", iconsArr);
NSLog(@"iconLastName: %@", iconLastName);
/*
打印日志:
iconsArr: (
AppIcon29x29,
AppIcon40x40,
AppIcon60x60
)
iconLastName: AppIcon60x60
*/
}
/** 获取app的启动图片名称,并设置为本控制器背景图片 */
- (void)getLaunchImageName{
NSString *launchImageName = @""; //启动图片名称变量
CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;
//获取与当前设备匹配的启动图片名称
if (screenHeight == 480){ //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){ // 6Plus, 6SPlus
launchImageName = @"LaunchImage-800-Landscape-736h";
}
if (launchImageName.length < 1) return;
//设备启动图片为控制器的背景图片
UIImage *img = [UIImage imageNamed:launchImageName];
self.view.backgroundColor = [UIColor colorWithPatternImage:img];
}

打印当前只支持iPhone设备并且只支持竖屏场景下的所有启动图片信息:

/** 打印app里面所有启动图片名称信息 */
- (void)printAllLaunchImageInfo{
 NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
 //获取所有启动图片信息数组
 NSArray *launchImagesArr = infoDict[@"UILaunchImages"];
 NSLog(@"launchImagesArr: %@", launchImagesArr);
 /*
 打印日志:启动图片的名字是固定的
 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}";
  }
 )
 */
}

看到了,项目AppIcon图标和启动图片信息,都可以从 [[NSBundle mainBundle] infoDictionary] 获得,当前这里面还包含了app的其他信息如版本、app名称、设备类型、支持方向。。。

打印所有信息看看:

/** 打印app工程配置信息 */
- (void)printInfoDictionary{
 NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
 NSLog(@"%@", infoDict);
 /*
 打印日志:
 {
  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
  );
 }
 */
}

---------- 接下来我们再来在app既支持iPhone和iPad设备,又支持横屏和竖屏时,AppIcon和LaunchImage是怎样的以及如何获取 ---

先上两张图,再上测试代码:

测试代码:

1、获取AppIcon所有icon图标名称

/** 支持iPhone和iPad, 获取app的icon图标名称 */
- (void)getAppIconName{
 NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
 //获取app中所有icon名字数组
 NSArray *iconsArr = infoDict[@"CFBundleIcons"][@"CFBundlePrimaryIcon"][@"CFBundleIconFiles"];
 //取最后一个icon的名字
 NSString *iconLastName = [iconsArr lastObject];
 //打印icon名字
 NSLog(@"iconsArr: %@", iconsArr);
 NSLog(@"iconLastName: %@", iconLastName);
 /*
 打印日志(29pt和40pt iPhone和iPad都用到;60pt --- iPhone, 76pt和83.5pt --- iPad):
 iconsArr: (
  AppIcon29x29,
  AppIcon40x40,
  AppIcon60x60,
  AppIcon76x76,
  "AppIcon83.5x83.5"
 )
 iconLastName: AppIcon83.5x83.5
 */
}

2、获取在支持iPhone和iPad开发,支持横屏和竖屏时,获取启动图片,并设为背景图片代码

(iPhone设备只有在Plus, 即5.5英寸才有竖屏和横屏两套图片,其他4、5、6竖屏横屏共用一张启动图片)

/**
 支持iPhone和iPad, 支持横屏、竖屏,
 获取app的启动图片名称,并设置为本控制器背景图片
 */
- (void)getLaunchImageName{
 NSString *launchImageName = @""; //启动图片名称变量
 CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height; //屏幕高度
 CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width; //屏幕宽度
 //设备界面方向
 UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
 BOOL isPortrait = UIInterfaceOrientationIsPortrait(orientation);// 是否竖屏
 BOOL isLandscape = UIInterfaceOrientationIsLandscape(orientation);//是否横屏
 //获取与当前设备匹配的启动图片名称
 //4、4S 竖屏,横屏
 if ((isPortrait && screenHeight == 480) || (isLandscape && screenWidth == 480)){
 launchImageName = @"LaunchImage-700";
 }
 //5、5C、5S、iPod 竖屏,横屏
 else if ((isPortrait && screenHeight == 568) || (isLandscape && screenWidth == 568)){
 launchImageName = @"LaunchImage-700-568h";
 }
 //6、6S 竖屏,横屏
 else if ((isPortrait && screenHeight == 667) || (isLandscape && screenWidth == 667)){
 launchImageName = @"LaunchImage-800-667h";
 }
 //6Plus、6SPlus竖屏
 else if (isPortrait && screenHeight == 736){
 launchImageName = @"LaunchImage-800-Portrait-736h";
 }
 //6Plus、6SPlus 横屏
 else if (isLandscape && screenWidth == 736){
 launchImageName = @"LaunchImage-800-Landscape-736h";
 }
 //iPad 竖屏
 else if (isPortrait && screenHeight == 1024){
 launchImageName = @"LaunchImage-700-Portrait";
 }
 //iPad 横屏
 else if (isLandscape && screenWidth == 1024){
 launchImageName = @"LaunchImage-700-Landscape";
 }
 if (launchImageName.length < 1) return;
 //设备启动图片为控制器的背景图片
 UIImage *img = [UIImage imageNamed:launchImageName];
 self.view.backgroundColor = [UIColor colorWithPatternImage:img];
}

3、打印出所有启动图片信息

/** 打印app里面所有启动图片名称信息 */
- (void)printAllLaunchImageInfo{
 NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
 //获取所有启动图片信息数组
 NSArray *launchImagesArr = infoDict[@"UILaunchImages"];
 NSLog(@"launchImagesArr: %@", launchImagesArr);
 /*
 打印日志:启动图片的名字是固定的
 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、打印所有配置信息

/** 打印app工程配置信息 */
- (void)printInfoDictionary{
 NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
 NSLog(@"%@", infoDict);
 /*
 打印日志:
 {
 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
      );
 }*/
}

以上所述是小编给大家介绍的iOS获取AppIcon and LaunchImage's name(app图标和启动图片名字),希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对我们网站的支持!

(0)

相关推荐

  • 用iOS代码获取APP启动页图片

    用代码获取APP启动页图片 // // AppleSystemService.swift // Swift-Animations // // Created by YouXianMing on 16/8/11. // Copyright © 2016年 YouXianMing. All rights reserved. // import UIKit class AppleSystemService : NSObject { /** Get the lauch image. - returns:

  • iOS中获取系统相册中的图片实例

    本文介绍了iOS中获取系统相册中的图片,在很多应用中都能用到,可以获取单张图片,也可以同时获取多张图片,废话不多说了,看下面吧. 一.获取单张图片 思路: 1.利用UIImagePickerController可以从系统自带的App(照片\相机)中获得图片 2.设置代理,遵守代理协议 注意这个UIImagePickerController类比较特殊,需要遵守两个代理协议 @interface ViewController () <UIImagePickerControllerDelegate,

  • iOS App中调用相册中图片及获取最近的一张图片的方法

    UIImagePickerController从拍照.图库.相册获取图片 iOS 获取图片有三种方法: 1. 直接调用摄像头拍照 2. 从相册中选择 3. 从图库中选择 UIImagePickerController 是系统提供的用来获取图片和视频的接口: 用UIImagePickerController 类来获取图片视频,大体分为以下几个步骤: 1. 初始化UIImagePickerController 类: 2. 设置UIImagePickerController 实例的数据来源类型(下面解

  • iOS开发之获取系统相册中的图片与视频教程(内带url转换)

    好些天没写点东西了,最近公司要做新项目,有点小忙.不想我的坚持就此中断,我把我前些天研究的东西拿出来给大家看看. 这次整理的是AssetsLibrary和PhotoKit的使用.本人处女座,有点强迫症,之前写的项目里用的是AssetsLibrary写的调取相册内的媒体文件,但是Xcode总是报警告错误,虽然能够编译并展示效果,但是十几个警告错误挂在那,心里总不是滋味,所以我就研究了一下AssetLibrary和PhotoKit. 在 iOS 8 出现之前,开发者只能使用 AssetsLibrar

  • iOS中读取照片库及保存图片或视频到照片库的要点解析

    读取照片库PhotoLibrary iOS中如果我们只有一次读取一张图片或者一个视频(或拍一张照片/视频)的需求,那么我们用 UIImagePickerController 就可以搞定.但是很多时候我们需要一次性从PhotoLibrary读取多个照片或者视频,这时候我们就需要另辟蹊径了,好在apple为我们提供了相应的接口. 在开始coding之前我们想要认识几个类: ALAssetsLibrary:代表整个PhotoLibrary,我们可以生成一个它的实例对象,这个实例对象就相当于是照片库的句

  • IOS开发代码分享之获取启动画面图片的string

    本代码支持 iPhone 6 以下. 支持 iPhone 及 iPad +(NSString*)getLaunchImageName {           NSArray* images= @[@"LaunchImage.png", @"LaunchImage@2x.png",@"LaunchImage-700@2x.png",@"LaunchImage-568h@2x.png",@"LaunchImage-700

  • iOS开发中用imageIO渐进加载图片及获取exif的方法

    imageIO完成渐进加载图片 一.常见渐进加载图片模式   目前我们看到的渐进加载主要有以下三种实现方式:   1)  依次从web上加载不同尺寸的图片,从小到大.最开始先拉取一个小缩略图做拉伸显示,然后拉取中等规格的图,拉取完毕直接覆盖显示,最后拉取原图,拉取完成后显示原图.   2)直接从web上拉取最大的图片,每接受一点儿数据就显示一点儿图片,这样就会实现从上到下一点点刷新出来的效果.   3)结合第1种和第2种,先拉取一个缩略图做拉伸显示,然后采用第二种方法直接拉取原图,这样即可以实现

  • iOS实现图片存在本地、再从本地获取图片的功能

    iOS实现图片存在本地.再从本地获取图片的功能,代码如下: //将图片保存到本地 + (void)SaveImageToLocal:(UIImage*)image Keys:(NSString*)key { NSUserDefaults* preferences = [NSUserDefaults standardUserDefaults]; //[preferences persistentDomainForName:LocalPath]; [preferences setObject:UII

  • iOS实现图片保存与搜索功能

    本文实现Photos.framework的常见功能,包括:创建自定义相册.保存图片到自定义相册.搜索所有相册的图片,具体内容如下 1.保存图片到相册 /** * 保存图片到相册 */ - (IBAction)saveImage { PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus]; if (status == PHAuthorizationStatusDenied) { NSLog(@"请到[设置-隐私-照片]

  • 深入分析iOS应用中对于图片缓存的管理和使用

    我们的 iOS 应用都包含了大量的图像.创建富有吸引力的视图,主要依赖于大量的装饰图片,所有这些首先必须从远程服务器获取.如果每次打开应用都要从服务器一次又一次的获取每个图像,那么用户体验肯定达不到好的效果,所以本地缓存远程图像是非常有必要的. 两种方式加载本地图片 1.通过imageNamed:方法加载图片 用过这种方式加载图片,一旦图片加载到内存中,那么就不会销毁,一直到程序退出.(也就是说imageNamed:会有图片缓存的功能,当下次访问图片的时候速度会更快.) 用这种方式加载图片,图片

随机推荐