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

  在某种场景下,可能我们需要获取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];

    // -----  打印app里面所有的启动图片信息 -----
    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
         );
     }
     */
}

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

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

时间: 2024-10-22 06:30:55

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

App图标和启动图片

各种图标尺寸 Icons for iPhone-only Applications iPhone-only applications use the following icons. Items marked with "Required" must be included. Note: You should include images for the iPad-specific icons even if the application is not a universal app

app图标和启动图以及Images.xcassets

概述 项目是纯代码编写,到现在一直没有适配iPhone6和iPhone6 plus,今天做了一些准备工作,app图标和启动图片的适配.项目当时是Xcode5创建的,并设置了app图标和启动图片(iPhone4到iPhone5s的图片).后来升级到Xcode6,因为没有适配iPhone6,app图标和启动图片也一直没改动. App Icons and Launch Images 选择General找到App Icons and Launch Images General Xcode5也是在这个地方

iOS App图标和启动画面尺寸

iOS App图标和启动画面尺寸 作者 简述呢 关注 注意:iOS所有图标的圆角效果由系统生成,给到的图标本身不能是圆角的. 1. 桌面图标 (app icon) for iPhone6 plus(@3x) : 180 x 180 for iPhone 6/5s/5/4s/4(@2x) : 120 x 120 2. 系统搜索框图标 (Spotlight search results icon) for iPhone6 plus(@3x) : 120 x 120 for iPhone6/5s/5/

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

第一.复制对象的基本概念 复制一个对象为副本,开辟一块新的内存来存储副本对象. 第二.如果一个对象想具备复制的功能,必须实现<NSCopying>协议和<NSMutableCopying>协议 NSObject自带的常用的对象有:NSNumber.NSString.NSArray.NSDictionary.NSMutableArray.NSMutableDictionay.NSMutableString,copy产生的对象时不可变的,mutableCopy产生的对象时可变的 第三.

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. 系统搜索框图标 (Spotlight search results icon) for iPhone6 plus(@3x) : 120 x 120 for iPhone6/5s/5/4s/4(@2x) : 80 x 80 3. 系统设置图标 (Settings icon) for iPhone6 plus(

[Xcode使用 2] 设置APP图标和启动画面

1.App Icon 把所有图标文件拖放到 "Images.xcassets" 的"AppIcon" 里面 应对非视网膜和视网膜屏,APP有时会提供两套不同大小的图片,1倍图和2倍图,它们的像素相差一倍. 命名规则:2倍图在1倍图的名字后加 @2x 普通:sample.png 2倍:[email protected] 系统用"sample"寻找图片的时候,会自动根据设备屏幕取对应的图片 2.修改启动画面 一个app在启动过程中会全屏显示叫做Def

ios 应用程序图标、启动画面、itune图标设置

http://blog.sina.com.cn/s/blog_4cd8dd1301014hfz.html 先说说应用程序图标,一般有下面几种: Icon.png(57x57) - Homescreen icon on iPhone/iPod touch [email protected](114x114) - Homescreen icon on iPhone 4 Icon-72(72x72) - Homescreen icon on iPad Icon-Small.png(29x29) - I

应用程序图标、启动图片

一Retain 所谓Retain屏幕,就是高清视网膜屏幕,分辨率宽高是标准屏幕分辨率的2倍 设备 屏幕类型 屏幕尺寸 分辨率 iPhone 3GS 非Retina 3.5 inch 320x480 iPhone4\4S Retina 3.5 inch 640x960 iPhone5\5C\5S Retina 4 inch 640x1136 二 应用程序启动图片(LaunchScreen) 一个app在启动过程中会全屏显示叫做Default.png的图片 不同规格Default的使用场合,以3.5

iOS 隐藏App图标

1.在进入Info.plist文件 2.在Info.plist文件中新添加一项,把Key值设置为SBAppTags,在Type选项中选取Array 3.在Array中新添加一项Item0,Type类型选择String,在点击后面空白处,输入hidden;然后运行程序便可实现隐藏App图标