在某种场景下,可能我们需要获取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 == ){ //4,4S
launchImageName = @"LaunchImage-700";
}
else if (screenHeight == ){ //5, 5C, 5S, iPod
launchImageName = @"LaunchImage-700-568h";
}
else if (screenHeight == ){ //6, 6S
launchImageName = @"LaunchImage-800-667h";
}
else if (screenHeight == ){ // 6Plus, 6SPlus
launchImageName = @"LaunchImage-800-Portrait-736h";
  } if (launchImageName.length < ) 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 = (
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
);
}
*/
}

----------- 接下来我们再来在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 == ) || (isLandscape && screenWidth == )){
launchImageName = @"LaunchImage-700";
}
//5、5C、5S、iPod 竖屏,横屏
else if ((isPortrait && screenHeight == ) || (isLandscape && screenWidth == )){
launchImageName = @"LaunchImage-700-568h";
}
//6、6S 竖屏,横屏
else if ((isPortrait && screenHeight == ) || (isLandscape && screenWidth == )){
launchImageName = @"LaunchImage-800-667h";
}
//6Plus、6SPlus竖屏
else if (isPortrait && screenHeight == ){
launchImageName = @"LaunchImage-800-Portrait-736h";
}
//6Plus、6SPlus 横屏
else if (isLandscape && screenWidth == ){
launchImageName = @"LaunchImage-800-Landscape-736h";
}
//iPad 竖屏
else if (isPortrait && screenHeight == ){
launchImageName = @"LaunchImage-700-Portrait";
}
//iPad 横屏
else if (isLandscape && screenWidth == ){
launchImageName = @"LaunchImage-700-Landscape";
} if (launchImageName.length < ) 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,
2
);
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
);
}*/ }

原文链接:http://www.cnblogs.com/tandaxia/p/5820217.html

iOS获取app图标和启动图片名字(AppIcon and LaunchImage's name)的更多相关文章

  1. iOS开发-APP图标、启动页、名字的设置

    APP图标.启动页.名字的设置:(较全面,但是APP启动页讲述的有漏洞) 参考链接:https://www.jianshu.com/p/2c7e181276ff APP启动页:(弥补上一文的漏洞) 参 ...

  2. APP图标和启动页

    iOS App图标和启动画面尺寸 字数349 阅读22025 评论3 喜欢51 注意:iOS所有图标的圆角效果由系统生成,给到的图标本身不能是圆角的. 1. 桌面图标 (app icon) for i ...

  3. React native 之android的图标和启动图片

    哎哎呀呀,上篇说到了react native的IOS的图标和启动图片的设置,其实最主要的是尺寸!相应的尺寸设定好了以后就不会报错了! ok~这篇说的是React native的android的图标和启 ...

  4. Mac生成APP图标和启动图的脚本

    概述 之前用的一个批量导出APP图标和启动图的软件,今天发现收费了,于是自己造了个简单的轮子. 实现 Mac上的sips命令,可以很方便的帮助用户修改图片尺寸 Xcode里面的APP启动图资源包含两部 ...

  5. [转载] IOS 获取网络图片的大小 改变 图片色值 灰度什么的方法集合

    IOS 获取网络图片的大小 改变 图片色值 灰度什么的方法集合

  6. LaunchImage命名与AppIcon命名(ios设置 启动图片和AppIcon图片)

    LaunchImage AppIcon 分别拖拉至Images.scassets  对应的LaunchImage和AppIcon就可以设置 启动图片和AppIcon图片

  7. react-native android app名字 app包名、图标和启动图片设置

    1.设置名字 打开 android/app/src/main/res/values/strings.xml 如图,进行修改即可 2.设置图标,最简单可以直接替换,其他后在看 在上图中几个文件夹中都有一 ...

  8. 16.iOS APP图标和启动画面尺寸

    1. 桌面图标 (app icon) for iPhone6 plus(@3x) : 180 x 180 for iPhone 6/5s/5/4s/4(@2x) : 120 x 120 2. 系统搜索 ...

  9. 34、iOS App图标和启动画面尺寸

    注意:iOS所有图标的圆角效果由系统生成,给到的图标本身不能是圆角的. 1. 桌面图标 (app icon) for iPhone6 plus(@3x) : 180 x 180 for iPhone ...

随机推荐

  1. 【repost】JS错误类型的学习

    SyntaxError是解析代码时发生的语法错误 // 变量名错误  var 1a;  // 缺少括号  console.log 'hello'); (2)ReferenceError Referen ...

  2. ASP.NET Core 性能对比评测(ASP.NET,Python,Java,NodeJS)

    前言 性能是我们日常生活中经常接触到的一个词语,更好的性能意味着能给我们带来更好的用户体检.比如我们在购买手机.显卡.CPU等的时候,可能会更加的关注于这样指标,所以本篇就来做一个性能评测. 性能也一 ...

  3. 【PRINCE2是什么】PRINCE2认证之七大原则(5)

    我们先来回顾一下,PRINCE2七大原则分别是持续的业务验证,经验学习,角色与责任,按阶段管理,例外管理,关注产品,剪裁. 第五个原则:例外管理. PRINCE2对每个项目目标都定义了容许偏差来建立授 ...

  4. 关于android中调用系统拍照,返回图片是旋转90度

    转载博客:http://blog.csdn.net/walker02/article/details/8211628 项目开发中遇到的一个问题,对于三星手机在做手机照片选择时出现图片显示不正常,研究后 ...

  5. ASP.NET MVC5+EF6+EasyUI 后台管理系统(17)-LinQ动态排序

    系列目录 首先修复程序中的一个BUG这个BUG在GridPager类中,把sord修改为sort这个名称填写错误,会导致后台一直无法获取datagrid的排序字段 本来是没有这一讲的,为了使20行的代 ...

  6. CGI与FastCGI

    当我们在谈到cgi的时候,我们在讨论什么 最早的Web服务器简单地响应浏览器发来的HTTP请求,并将存储在服务器上的HTML文件返回给浏览器,也就是静态html.事物总是不 断发展,网站也越来越复杂, ...

  7. Vertica增加一个数据存储的目录

    Vertica增加一个数据存储的目录 操作语法为: ADD_LOCATION ( 'path' , [ 'node' , 'usage', 'location_label' ] ) 各节点添加目录,并 ...

  8. 网站实现微信登录之嵌入二维码——基于yii2开发的描述

    之前写了一篇yii2获取登录前的页面url地址的文章,然后发现自己对于网站实现微信扫码登录功能的实现不是很熟悉,所以,我会写2-3篇的文章来描述下一个站点如何实现微信扫码登录的功能,来复习下微信扫码登 ...

  9. 1.JAVA之GUI编程概述

          下列内容为本人看毕向东老师java视频教程学习笔记! JAVA GUI图形用户界面编程: Windows 操作系统提供两种操作方式:                             ...

  10. 重定向Http status code 303 和 302

    http 302 http 303 Http 302 302是一个普通的重定向代码.直观的看来是,请求者(浏览器或者模拟http请求)发起一个请求,然后服务端重定向到另一个地址.而事实上,服务端仅仅是 ...