Non gestisco più manualmente i framework ma uso e recommendCocoaPods invece.
risposta originale:
- Utilizzare la fake framework @ wattson12 menzionato. Compilerà e salverà anche le risorse.
Ispirato this script, aggiungere questo al vostro obiettivo per copiare le risorse per la vostra applicazione:
SOURCE_PATH="${TARGET_BUILD_DIR}/MYFramework.framework/Resources/"
TARGET_PATH="${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/MYFrameworkResources.bundle"
mkdir -p $TARGET_PATH
cp -R $SOURCE_PATH $TARGET_PATH
Si potrebbe anche solo trascinare il quadro di riferimento per il vostro passo Copia risorse, ma allora sarete aggiungendo intestazioni non necessarie e codice compilato pure.
Modifica
Per utilizzare queste risorse da IB, per esempio un file PNG, sostituire:
MyImage
da:
MYFrameworkResources.bundle/MyImage.png
Sarà l'anteprima di un'immagine icona rotto, ma funzionerà durante l'esecuzione.
Caricare un pennino dal codice:
[NSBundle loadNibNamed:@"MYFrameworkResources.bundle/MyNib" ...
Infine è possibile aggiungere questi metodi in una categoria NSBundle per facilitare l'accesso alle risorse pennino che il mio essere nel vostro pacchetto principale o in MYFrameworkResources.bundle:
@implementation NSBundle (MyCategory)
+ (NSString *)pathForResource:(NSString *)name
ofType:(NSString *)extension
{
// First try with the main bundle
NSBundle * mainBundle = [NSBundle mainBundle];
NSString * path = [mainBundle pathForResource:name
ofType:extension];
if (path)
{
return path;
}
// Otherwise try with other bundles
NSBundle * bundle;
for (NSString * bundlePath in [mainBundle pathsForResourcesOfType:@"bundle"
inDirectory:nil])
{
bundle = [NSBundle bundleWithPath:bundlePath];
path = [bundle pathForResource:name
ofType:extension];
if (path)
{
return path;
}
}
NSLog(@"No path found for: %@ (.%@)", name, extension);
return nil;
}
+ (NSArray *)loadNibNamed:(NSString *)name
owner:(id)owner
options:(NSDictionary *)options
{
// First try with the main bundle
NSBundle * mainBundle = [NSBundle mainBundle];
if ([mainBundle pathForResource:name
ofType:@"nib"])
{
NSLog(@"Loaded Nib named: '%@' from mainBundle", name);
return [mainBundle loadNibNamed:name
owner:owner
options:options];
}
// Otherwise try with other bundles
NSBundle * bundle;
for (NSString * bundlePath in [mainBundle pathsForResourcesOfType:@"bundle"
inDirectory:nil])
{
bundle = [NSBundle bundleWithPath:bundlePath];
if ([bundle pathForResource:name
ofType:@"nib"])
{
NSLog(@"Loaded Nib named: '%@' from bundle: '%@' ", name, bundle.bundleIdentifier);
return [bundle loadNibNamed:name
owner:owner
options:options];
}
}
NSLog(@"Couldn't load Nib named: %@", name);
return nil;
}
@end
si cercherà prima nella vostra bundle dell'applicazione e poi in MYFrameworkResources.bundle, ecc
Hi Andrei, puoi dirmi come si aggiunge il file nella directory .bundle quadro ... i non sono in grado di farlo. potrebbe esserci qualche errore nel mio script di shell. – Apple