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

在某种场景下,可能我们需要获取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图标和启动图片名字),希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!

以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索ios
, 获取launchimage
aapicon
获取launchimage、ios launchimage 获取、quick launch icon、launch icon、ios launchimage 尺寸,以便于您获取更多的相关知识。

时间: 2024-10-29 03:38:09

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

ios-iOS 推送来时有时点击app图标也会跳转 我已经贴了代码 希望大家能帮忙解决真的烦扰我很久了

问题描述 iOS 推送来时有时点击app图标也会跳转 我已经贴了代码 希望大家能帮忙解决真的烦扰我很久了 我用的是个推的SDK 1.我先说我想达到的目的以及问题: a.在前台不能点击通知栏跳转且通知栏不显示通知信息 b.在后台(程序未杀死)通知栏显示通知信息且点击通知栏的信息会跳转到某个controller,但是点击app图标不会跳转 (这是出问题的地方,就是我有的时候来通知了 点击app图标进入应用,是正常的不会跳转,但偶尔也会跳转) c.程序杀死后通知栏显示通知信息且点击通知栏的信息会跳转到

app列表图标-ios 如何获取手机安装的所有App列表,并获取到App图标。

问题描述 ios 如何获取手机安装的所有App列表,并获取到App图标. 这个方法获取到了 但听说上不了AppStore 而且只实现获取列表没有图标 //#pragma mark 获取手机内安装的程序 Class LSApplicationWorkspace_class = objc_getClass("LSApplicationWorkspace"); NSObject* workspace = [LSApplicationWorkspace_class performSelecto

获取Android手机型号,系统版本,App版本号等信息

 MainActivity如下: package cn.testgethandsetinfo; import android.os.Bundle; import android.text.TextUtils; import android.widget.TextView; import android.app.Activity; import android.content.Context; import android.content.pm.PackageInfo; import androi

IOS获取通讯录联系人信息

IOS获取系统通讯录联系人信息 一.权限注册 随着apple对用户隐私的越来越重视,IOS系统的权限设置也更加严格,在获取系统通讯录之前,我们必须获得用户的授权.权限申请代码示例如下: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31     //这个变量用于记录授权是否成功,即用户是否允许我们访问通讯录     int __block tip=0;     //声明一个通讯

设备-ios 获取蓝牙配对信息

问题描述 ios 获取蓝牙配对信息 有没有人做过IOS BLE 相关的应用,有一个问题,在IOS app里面怎么获取系统setting里面已经配对过的蓝牙设备的信息呢? 解决方案 http://www.raywenderlich.com/52080/introduction-core-bluetooth-building-heart-rate-monitor 解决方案二: 参考这篇老外的博客 介绍的是iphone通过蓝牙链接一台心跳检测仪,有详细介绍和代码 解决方案三: 参考这篇老外的博客 介绍

详解iOS获取通讯录的4种方式_IOS

本文实例为大家分享了iOS获取通讯录的4种方式,供大家参考,具体内容如下 使用场景 一些App通过手机号码来推荐好友,如 微博.支付宝 首先客户端会获取通讯录中的所有手机号然后将这些手机号提交到App服务器中,服务器会查找每个手机号对应的App账号如QQ号码返回到客户端,然后客户端根据服务器返回的账号列表来推荐好友. 获取联系人方式 方案一:AddressBookUI.framework框架 提供了联系人列表界面.联系人详情界面.添加联系人界面等 一般用于选择联系人 方案二:AddressBoo

IOS获取缓存文件的大小并清除缓存文件的方法_IOS

移动应用在处理网络资源时,一般都会做离线缓存处理,其中以图片缓存最为典型,其中很流行的离线缓存框架为SDWebImage. 但是,离线缓存会占用手机存储空间,所以缓存清理功能基本成为资讯.购物.阅读类app的标配功能. 今天介绍的离线缓存功能的实现,主要分为缓存文件大小的获取.清除缓存文件的实现. 1. 获取缓存文件的大小 -( float )readCacheSize { NSString *cachePath = [NSSearchPathForDirectoriesInDomains (N

iOS获取当前设备型号等信息(全)包含iPhone7和iPhone7P_IOS

#include <sys/types.h> #include <sys/sysctl.h> //获得设备型号 + (NSString *)getCurrentDeviceModel { int mib[2]; size_t len; charchar *machine; mib[0] = CTL_HW; mib[1] = HW_MACHINE; sysctl(mib, 2, NULL, &len, NULL, 0); machine = malloc(len); sysc

iOS获取设备唯一标识的8种方法_IOS

8种iOS获取设备唯一标识的方法,希望对大家有用. UDID UDID(Unique Device Identifier),iOS 设备的唯一识别码,是一个40位十六进制序列(越狱的设备通过某些工具可以改变设备的 UDID),移动网络可以利用 UDID 来识别移动设备. 许多开发者把 UDID 跟用户的真实姓名.密码.住址.其它数据关联起来,网络窥探者会从多个应用收集这些数据,然后顺藤摸瓜得到这个人的许多隐私数据,同时大部分应用确实在频繁传输 UDID 和私人信息. 为了避免集体诉讼,苹果最终决