I'm looking for a way to check if a framework exists and/or if it's classes are defined, before importing and using that framework. Specifically, the framework is Assets Library.
Currently, I'm able to do this with the Core Data framework, since that framework has a file called CoreDataDefines.h which provides a preprocessor directive _COREDATADEFINES_H. This allows me to simply check for that defintion like so:
#ifdef _COREDATADEFINES_H
#import <CoreData/CoreData.h>
// do something with Core Data
#else
// do something without using Core Data
#endif
Unfortunately, the Assets Library does not provide a clear definitions header file so I'm looking for a way to write my own #define statement that can check for the framework's existence before importing it, much like I have done for Core Data above.
I have tried this:
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 40000
// import assets library if defined !
#define ASSETSLIBRARY_DEFINE (NSClassFromString(@"ALAsset") != nil)
#if ASSETSLIBRARY_DEFINE
#import <AssetsLibrary/AssetsLibrary.h>
#endif
#endif
... but no luck.
The compiler tells me that the "Token is not a valid binary operator in a preprocessor subexpression."
Any help is always much appreciated.
If you know what class should be imported with the framework you can check if it is loaded:
BOOL isFrameworkLoaded = (NSClassFromString(@"MyClassNameFromTheFramework") != nil);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With