iOS获取AppIcon and LaunchImage's name(app图标和启动图片名字)
作者:mrr 发布时间:2022-01-11 02:39:14
在某种场景下,可能我们需要获取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图标和启动图片名字)网站的支持!


猜你喜欢
- 本文实例讲述了Java基于链表实现栈的方法。分享给大家供大家参考,具体如下:在上几小节中我们实现了基本的链表结构,并在上一节的底部给出了有关
- 本文实例形式展示了C#中异步调用的实现方法,并对其原理进行了较为深入的分析,现以教程的方式分享给大家供大家参考之用。具体如下:首先我们来看一
- 本文实例讲述了Java递归算法。分享给大家供大家参考,具体如下:1.实现1到100的和,用递归实现public class Recursio
- package com.test; import java.io.FileNotFoundException;&nbs
- 1、Aware 系列接口Aware 系列接口是用来获取 Spring 内部对象的接口。Aware 自身是一个顶级接口,它有一系列子接口,在一
- 什么是委托?委托是寻址方法的.NET版本,使用委托可以将方法作为参数进行传递。委托是一种特殊类型的对象,其特殊之处在于委托中包含的只是一个活
- Android M(6.0)API 23后加入了权限请求设置,APP需要使用某些权限需要主动申请。权限分为3类,一组是Normal权限,无需
- 1.Feign传统方式的不足①.在微服务架构中,当我们使用Feign传统方式进行服务调用的时候,需要在每个服务消费者中添加FeignClie
- 配置文件<!-- 文件上传 --> <bean id="multipartResolver" clas
- 目录@ConfigurationProperties使用@ConfigurationProperties特点宽松绑定支持复杂属性类型激活@C
- 一、线程池使用场景•单个任务处理时间短•将需处理的任务数量大二、使用Java线程池好处1、使用new Thread()创建线程的弊端:•每次
- 概述ReentrantReadWriteLock不知道大家熟悉吗?其实在实际的项目中用的比较少,反正我所在的项目没有用到过。Reentran
- 1.首先什么是JNI呢?JNI——(Java Native Interface),他是java平台的特性,不是安卓系统提供的。他定义了一些J
- 目录算术操作符移位操作符位操作符赋值操作符 单目操作符(类型) 强制类型转换 &n
- 前言:已经有一个月没写点什么了,感觉心里空落落的。今天再来篇干货,想要学习Webapi的园友们速速动起来,跟着博主一起来学习吧。之前分享过一
- /** * 实现 * @author dujinyang * */顺序是: OneAcitivity
- 前言请看下面几个问题Spring为什么不推荐使用@Autowired 注解?为什么推荐使用@Resource 代替&nb
- Java RandomAccessFile 指定位置实现文件读取与写入RandomAccessFile是属于随机读取类,是可以对文件本身的内
- 本文实例讲述了Java基于分治算法实现的棋盘覆盖问题。分享给大家供大家参考,具体如下:在一个2^k * 2^k个方格组成的棋盘中,有一个方格
- 引言最近在工作中结合线程池使用 InheritableThreadLocal 出现了获取线程变量“错误&rdqu