跳到主要内容

CDVAvaliability.h 源码分析

// 定义了 cordova ios
#define __CORDOVA_IOS__

// 定义了各个版本号
#define __CORDOVA_0_9_6 906
......
#define __CORDOVA_3_6_1 30601
#define __CORDOVA_3_6_3 30603
#define __CORDOVA_NA 99999 /* not available */

// 如果定义了 CORDOVA_VERSION_MIN_REQUIRED,则将其赋值为最新版本
#ifndef CORDOVA_VERSION_MIN_REQUIRED
#define CORDOVA_VERSION_MIN_REQUIRED __CORDOVA_3_6_3
#endif

// 用于为特定的 IOS 版本执行特定的操作
#define IsAtLeastiOSVersion(X) ([[[UIDevice currentDevice] systemVersion] compare:X options:NSNumericSearch] != NSOrderedAscending)

// 判断 iPad
#define CDV_IsIPad() ([[UIDevice currentDevice] respondsToSelector:@selector(userInterfaceIdiom)] && ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad))

// 通过显示界面大小判断 iPhone5
#define CDV_IsIPhone5() ([[UIScreen mainScreen] bounds].size.height == 568 && [[UIScreen mainScreen] bounds].size.width == 320)

// 返回版本号
/* Return the string version of the decimal version */
#define CDV_VERSION [NSString stringWithFormat:@"%d.%d.%d", \
(CORDOVA_VERSION_MIN_REQUIRED / 10000), \
(CORDOVA_VERSION_MIN_REQUIRED % 10000) / 100, \
(CORDOVA_VERSION_MIN_REQUIRED % 10000) % 100]


// 定义显示过时的方法
#ifdef __clang__
#define CDV_DEPRECATED(version, msg) __attribute__((deprecated("Deprecated in Cordova " #version ". " msg)))
#else
#define CDV_DEPRECATED(version, msg) __attribute__((deprecated()))
#endif

// 开启 Log
// Enable this to log all exec() calls.
#define CDV_ENABLE_EXEC_LOGGING 0
#if CDV_ENABLE_EXEC_LOGGING
#define CDV_EXEC_LOG NSLog
#else
#define CDV_EXEC_LOG(...) do {} while (NO)
#endif