项目在 Archive
打包后,生成ipa
包
将 xxx.ipa
文件修改为zip
后缀即 xxx.zip
,然后再双击解压,会生成一个 Payload
文件夹,里面一个文件 如下图:
然后显示改文件的包内容:
解压 Assets.car
文件的方式:
方法一、 插件 AssetCatalogTinkerer
下载插件 AssetCatalogTinkerer ,用【My Mac】模拟器运行,然后 Assets.car
使用 AssetCatalogTinkerer
打开 ,如下图:
可以选择到处一张图片,也可选择到处所有图片:
方式二、插件 cartool
下载插件 cartool ,用【My Mac】模拟器运行,这时候会报错,替换main.m
文件内容,如下:
//
// main.m
// cartool
//
// Created by Steven Troughton-Smith on 14/07/2013.
// Copyright (c) 2013 High Caffeine Content. All rights reserved.
//#import <Foundation/Foundation.h>
#import <ImageIO/ImageIO.h>typedef enum _kCoreThemeIdiom {kCoreThemeIdiomUniversal,kCoreThemeIdiomPhone,kCoreThemeIdiomPad,kCoreThemeIdiomTV,kCoreThemeIdiomCar,kCoreThemeIdiomWatch,kCoreThemeIdiomMarketing
} kCoreThemeIdiom;typedef NS_ENUM(NSInteger, UIUserInterfaceSizeClass) {UIUserInterfaceSizeClassUnspecified = 0,UIUserInterfaceSizeClassCompact = 1,UIUserInterfaceSizeClassRegular = 2,
};@interface CUICommonAssetStorage : NSObject-(NSArray *)allAssetKeys;
-(NSArray *)allRenditionNames;-(id)initWithPath:(NSString *)p;-(NSString *)versionString;@end@interface CUINamedImage : NSObject@property(readonly) CGSize size;
@property(readonly) CGFloat scale;
@property(readonly) kCoreThemeIdiom idiom;
@property(readonly) UIUserInterfaceSizeClass sizeClassHorizontal;
@property(readonly) UIUserInterfaceSizeClass sizeClassVertical;-(CGImageRef)image;@end@interface CUIRenditionKey : NSObject
@end@interface CUIThemeFacet : NSObject+(CUIThemeFacet *)themeWithContentsOfURL:(NSURL *)u error:(NSError **)e;@end@interface CUICatalog : NSObject@property(readonly) bool isVectorBased;-(id)initWithURL:(NSURL *)URL error:(NSError **)error;
-(id)initWithName:(NSString *)n fromBundle:(NSBundle *)b;
-(id)allKeys;
-(id)allImageNames;
-(CUINamedImage *)imageWithName:(NSString *)n scaleFactor:(CGFloat)s;
-(CUINamedImage *)imageWithName:(NSString *)n scaleFactor:(CGFloat)s deviceIdiom:(int)idiom;
-(NSArray *)imagesWithName:(NSString *)n;@endvoid CGImageWriteToFile(CGImageRef image, NSString *path)
{CFURLRef url = (__bridge CFURLRef)[NSURL fileURLWithPath:path];CGImageDestinationRef destination = CGImageDestinationCreateWithURL(url, kUTTypePNG, 1, NULL);CGImageDestinationAddImage(destination, image, nil);if (!CGImageDestinationFinalize(destination)) {NSLog(@"Failed to write image to %@", path);}CFRelease(destination);
}NSString *idiomSuffixForCoreThemeIdiom(kCoreThemeIdiom idiom)
{switch (idiom) {case kCoreThemeIdiomUniversal:return @"";break;case kCoreThemeIdiomPhone:return @"~iphone";break;case kCoreThemeIdiomPad:return @"~ipad";break;case kCoreThemeIdiomTV:return @"~tv";break;case kCoreThemeIdiomCar:return @"~carplay";break;case kCoreThemeIdiomWatch:return @"~watch";break;case kCoreThemeIdiomMarketing:return @"~marketing";break;default:break;}return @"";
}NSString *sizeClassSuffixForSizeClass(UIUserInterfaceSizeClass sizeClass)
{switch (sizeClass){case UIUserInterfaceSizeClassCompact:return @"C";break;case UIUserInterfaceSizeClassRegular:return @"R";break;default:return @"A";}
}NSMutableArray *getImagesArray(CUICatalog *catalog, NSString *key)
{NSMutableArray *images = [[NSMutableArray alloc] initWithCapacity:5];for (NSNumber *scaleFactor in @[@1, @2, @3]){CUINamedImage *image = [catalog imageWithName:key scaleFactor:scaleFactor.doubleValue];if (image && image.scale == scaleFactor.floatValue) [images addObject:image];}return images;
}void exportCarFileAtPath(NSString * carPath, NSString *outputDirectoryPath)
{NSError *error = nil;outputDirectoryPath = [outputDirectoryPath stringByExpandingTildeInPath];// CUIThemeFacet *facet = [CUIThemeFacet themeWithContentsOfURL:[NSURL fileURLWithPath:carPath] error:&error];
//
// CUICatalog *catalog = [[CUICatalog alloc] init];// 替换成以下代码CUICatalog *catalog = nil;if ([CUICatalog instancesRespondToSelector:@selector(initWithURL:error:)]) {/* If CUICatalog has the URL API (Mojave), use it. */catalog = [[CUICatalog alloc] initWithURL:[NSURL fileURLWithPath:carPath] error:&error];} else {CUIThemeFacet *facet = [CUIThemeFacet themeWithContentsOfURL:[NSURL fileURLWithPath:carPath] error:&error];catalog = [[CUICatalog alloc] init];/* Override CUICatalog to point to a file rather than a bundle */[catalog setValue:facet forKey:@"_storageRef"];}/* Override CUICatalog to point to a file rather than a bundle */
// [catalog setValue:facet forKey:@"_storageRef"];/* CUICommonAssetStorage won't link */CUICommonAssetStorage *storage = [[NSClassFromString(@"CUICommonAssetStorage") alloc] initWithPath:carPath];for (NSString *key in [storage allRenditionNames]){printf("%s\n", [key UTF8String]);NSArray* pathComponents = [key pathComponents];if (pathComponents.count > 1){// Create subdirectories for namespaced assets (those with names like "some/namespace/image-name")NSArray* subdirectoryComponents = [pathComponents subarrayWithRange:NSMakeRange(0, pathComponents.count - 1)];NSString* subdirectoryPath = [outputDirectoryPath copy];for (NSString* pathComponent in subdirectoryComponents){subdirectoryPath = [subdirectoryPath stringByAppendingPathComponent:pathComponent];}[[NSFileManager defaultManager] createDirectoryAtPath:subdirectoryPathwithIntermediateDirectories:YESattributes:nilerror:&error];}NSMutableArray *images = getImagesArray(catalog, key);for( CUINamedImage *image in images ){if( CGSizeEqualToSize(image.size, CGSizeZero) )printf("\tnil image?\n");else{CGImageRef cgImage = [image image];NSString *idiomSuffix = idiomSuffixForCoreThemeIdiom(image.idiom);NSString *sizeClassSuffix = @"";if (image.sizeClassHorizontal || image.sizeClassVertical){sizeClassSuffix = [NSString stringWithFormat:@"-%@x%@", sizeClassSuffixForSizeClass(image.sizeClassHorizontal), sizeClassSuffixForSizeClass(image.sizeClassVertical)];}NSString *scale = image.scale > 1.0 ? [NSString stringWithFormat:@"@%dx", (int)floor(image.scale)] : @"";NSString *name = [NSString stringWithFormat:@"%@%@%@%@.png", key, idiomSuffix, sizeClassSuffix, scale];printf("\t%s\n", [name UTF8String]);if( outputDirectoryPath )CGImageWriteToFile(cgImage, [outputDirectoryPath stringByAppendingPathComponent:name]);}}}
}int main(int argc, const char * argv[])
{@autoreleasepool {if (argc < 2){printf("Usage: cartool <path to Assets.car> [outputDirectory]\n");return -1;}exportCarFileAtPath([NSString stringWithUTF8String:argv[1]], argc > 2 ? [NSString stringWithUTF8String:argv[2]] : nil);}return 0;
}
然后修改 Edit Scheme
,如下:
设置好两个路径:
1.Assert.car文件的路径,我是放在桌面的上的,所以路径为:
/Users/xxx/Desktop/Assets.car
2.解压后的资源存在的路径,这里是一个文件夹路径,我是在桌面创建一个名为img
的文件夹,所以路径为:
/Users/xxx/Desktop/img
替换完main.m文件,设置好路径后就可以运行该项目,然后可以看到控制台一直在输出内容,解压完成后,可以查看 img 文件夹里面解压后的资源图片 :
我们项目中是用的是 pdf
矢量图,所以打包后会自动生成 @1x、@2x、@3x图片,已适配不同分辨率的机型。