获取APP的图标和启动图
2018-12-26 本文已影响38人
黑暗森林的歌者
公司的app又新的需求,在某些地方会用到app的图标和启动图,但是图标和启动图放在系统的文件夹里,获取这些图标的方式和一般加载资源的方式不一样。
获取图标
NSDictionary *APPInfo = [[NSBundle mainBundle] infoDictionary];
NSArray *appIcons = APPInfo[@"CFBundleIcons"][@"CFBundlePrimaryIcon"][@"CFBundleIconFiles"];
UIImage *icon = appIcons.lastObject;
获取启动图
NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
NSArray *launchImageArr = infoDict[@"UILaunchImages"];
// 这个数组中就是启动
// 可以根据屏幕的高度获取对应的图片
UILaunchImages = (
{
UILaunchImageMinimumOSVersion = "12.0";
UILaunchImageName = "LaunchImage-1200-Portrait-2688h";
UILaunchImageOrientation = Portrait;
UILaunchImageSize = "{414, 896}";
},
{
UILaunchImageMinimumOSVersion = "12.0";
UILaunchImageName = "LaunchImage-1200-Portrait-1792h";
UILaunchImageOrientation = Portrait;
UILaunchImageSize = "{414, 896}";
},
{
UILaunchImageMinimumOSVersion = "11.0";
UILaunchImageName = "LaunchImage-1100-Portrait-2436h";
UILaunchImageOrientation = Portrait;
UILaunchImageSize = "{375, 812}";
},
{
UILaunchImageMinimumOSVersion = "8.0";
UILaunchImageName = "LaunchImage-800-Portrait-736h";
UILaunchImageOrientation = Portrait;
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}";
}
);
获取app的其他信息
如果需要获取app的名字版本号等等都可以从info的字典中获取,具体的对应的key可以打印出来
Printing description of infoDict:
{
BuildDate = "2018-12-26";
BuildMachineOSBuild = 18C54;
CFBundleDevelopmentRegion = en;
CFBundleDisplayName = "\U6c83\U5b66\U5802-new";
CFBundleExecutable = UnicomProject;
CFBundleIcons = {
CFBundlePrimaryIcon = {
CFBundleIconFiles = (
AppIcon60x60
);
CFBundleIconName = AppIcon;
};
};
CFBundleIdentifier = "io.github.dongjiawang.UnicomProject";
CFBundleInfoDictionaryVersion = "6.0";
CFBundleName = UnicomProject;
CFBundleNumericVersion = 16809984;
CFBundlePackageType = APPL;
CFBundleShortVersionString = "1.0";
CFBundleSupportedPlatforms = (
iPhoneSimulator
);
CFBundleVersion = 1;
DTCompiler = "com.apple.compilers.llvm.clang.1_0";
DTPlatformBuild = 10B61;
DTPlatformName = iphonesimulator;
DTPlatformVersion = "12.1";
DTSDKBuild = 16B91;
DTSDKName = "iphonesimulator12.1";
DTXcode = 1010;
DTXcodeBuild = 10B61;
LSRequiresIPhoneOS = 1;
MinimumOSVersion = "11.0";
NSAppTransportSecurity = {
NSAllowsArbitraryLoads = 1;
NSExceptionDomains = {
"qimooc.com" = {
NSExceptionAllowsInsecureHTTPLoads = 1;
NSExceptionRequiresForwardSecrecy = 0;
NSIncludesSubdomains = 1;
};
};
};
NSCameraUsageDescription = "\U8bf7\U5141\U8bb8\U6253\U5f00\U6444\U50cf\U5934";
UIDeviceFamily = (
1
);
UILaunchImageFile = LaunchImage;
UILaunchImages = (
{
UILaunchImageMinimumOSVersion = "12.0";
UILaunchImageName = "LaunchImage-1200-Portrait-2688h";
UILaunchImageOrientation = Portrait;
UILaunchImageSize = "{414, 896}";
},
{
UILaunchImageMinimumOSVersion = "12.0";
UILaunchImageName = "LaunchImage-1200-Portrait-1792h";
UILaunchImageOrientation = Portrait;
UILaunchImageSize = "{414, 896}";
},
{
UILaunchImageMinimumOSVersion = "11.0";
UILaunchImageName = "LaunchImage-1100-Portrait-2436h";
UILaunchImageOrientation = Portrait;
UILaunchImageSize = "{375, 812}";
},
{
UILaunchImageMinimumOSVersion = "8.0";
UILaunchImageName = "LaunchImage-800-Portrait-736h";
UILaunchImageOrientation = Portrait;
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}";
}
);
UIRequiredDeviceCapabilities = (
armv7
);
UISupportedInterfaceOrientations = (
UIInterfaceOrientationPortrait
);
}