IOS - 常用开发Tips(二公共适配部分常用宏)
(2014-03-01 17:45:56)
标签:
ios-常用开发tipit |
分类: Mac/IOS那些事 |
ottool -l ; 这个方法可以列出你的二进制可执行文件所link的所有的libraries,如果你link了类似WebKit这类的东西,那说明你肯定使用了私有API。
nm -u
最后一个可以猜到的方法:由于objc的方法存储在你的可执行文件的一个固定的区域,Apple绝对有工具把那块区域的内容直接翻译成文本并检查所有的方法中有没有私有API方法。
2 . runtime提供的功能确实强大,但是你真的要使用私有API,还是有风险的,苹果还有运行时的沙盒测试,把你的程序
以上都来源于我长期的实践和网络上的资料, 没有任何官方文档说明,仅作参考。
我曾经在代码中使用过runtime来替换系统框架的某个方法来达到实现自己的目的,程序没有被拒绝。
我也曾经在一个完整的使用公开API的程序中,尝试加入了一个对私有API的引用(不使用它的任何方法),程序直接被拒,原因就是使用了私有API。
6
公共宏定义
#define SCREENWIDTH [UIScreen mainScreen].bounds.size.width
#define SCREENHEIGHT [UIScreen mainScreen].bounds.size.height
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
#define iPhone5 ([UIScreen
instancesRespondToSelect
#define IOS7 (([[[UIDevice currentDevice] systemVersion] floatValue] >= 7 )? 1:NO)
----------------------------一下来自github文件------------------------
https://github.com/zhangxigithub/ZXMicro
2013.3.26
*/
//------------------------------------Debug/Release
#ifdef DEBUG
//Debug模式
//...
#else
//发布模式
//...
//屏蔽NSLog
#define NSLog(...) {};
#endif
//------------------------------------Simulator/Device
//区分模拟器和真机
#if TARGET_OS_IPHONE
//iPhone Device
#endif
#if TARGET_IPHONE_SIMULATOR
//iPhone Simulator
#endif
//------------------------------------ARC/no RAC
//ARC
#if __has_feature(objc_arc)
//compiling with ARC
#else
// compiling without ARC
#endif
//Block
typedef void(^VoidBlock)();
typedef BOOL(^BoolBlock)();
typedef int (^IntBlock) ();
typedef id
typedef void(^VoidBlock_int)(int);
typedef BOOL(^BoolBlock_int)(int);
typedef int (^IntBlock_int) (int);
typedef id
typedef void(^VoidBlock_string)(NSString*);
typedef BOOL(^BoolBlock_string)(NSString*);
typedef int (^IntBlock_string) (NSString*);
typedef id
typedef void(^VoidBlock_id)(id);
typedef BOOL(^BoolBlock_id)(id);
typedef int (^IntBlock_id) (id);
typedef id
//System
#define PasteString(string)
#define PasteImage(image)
//Image
//可拉伸的图片
#define ResizableImage(name,top,left,bottom,right) [[UIImage
imageNamed:name]
resizableImageWithCapIns
#define ResizableImageWithMode(name,top,left,bottom,right,mode)
[[UIImage imageNamed:name]
resizableImageWithCapIns
//file
//读取文件的文本内容,默认编码为UTF-8
#define FileString(name,ext)
#define FileDictionary(name,ext)
#define FileArray(name,ext)
//数学
#define PI 3.14159
//输出frame(frame是结构体,没法%@)
#define LOGFRAME(f) NSLog(@"\nx:%f\ny:%f\nwidth:%f\nheight:%f\n",f.origin.x,f.origin.y,f.size.width,f.size.height)
#define LOGBOOL(b)
//弹出信息
#define ALERT(msg) [[[UIAlertView alloc] initWithTitle:nil message:msg delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil] show]
//App
#define kApp ((AppDelegate *)[UIApplication sharedApplication].delegate)
#define kNav ((AppDelegate *)[UIApplication sharedApplication].delegate.navigationController)
//color
#define RGB(r, g, b)
#define RGBAlpha(r, g, b, a)
#define HexRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
#define HexRGBAlpha(rgbValue,a) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:(a)]
//转换
#define I2S(number) [NSString stringWithFormat:@"%d",number]
#define F2S(number) [NSString stringWithFormat:@"%f",number]
#define DATE(stamp) [NSDate dateWithTimeIntervalSinc
//设备屏幕尺寸
#define kScreen_Height
#define kScreen_Width
#define kScreen_Frame
#define kScreen_CenterX
#define kScreen_CenterY
//应用尺寸(不包括状态栏,通话时状态栏高度不是20,所以需要知道具体尺寸)
#define kContent_Height
#define kContent_Width
#define kContent_Frame
#define kContent_CenterX
#define kContent_CenterY
#define kP1 CGPointMake(0
#define kP2 CGPointMake(kContent_Width/2
#define kP3 CGPointMake(kContent_Width
#define kP4 CGPointMake(0
#define kP5 CGPointMake(kContent_Width/2
#define kP6 CGPointMake(kContent_Width
#define kP7 CGPointMake(0
#define kP8 CGPointMake(kContent_Width/2
#define kP9 CGPointMake(kContent_Width
//*********************************************
//GCD
#define BACK(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)
#define MAIN(block) dispatch_async(dispatch_get_main_queue(),block)
//Device
#define isIOS4 ([[[UIDevice currentDevice] systemVersion] intValue]==4)
#define isIOS5 ([[[UIDevice currentDevice] systemVersion] intValue]==5)
#define isIOS6 ([[[UIDevice currentDevice] systemVersion] intValue]==6)
#define isAfterIOS4 ([[[UIDevice currentDevice] systemVersion] intValue]>4)
#define isAfterIOS5 ([[[UIDevice currentDevice] systemVersion] intValue]>5)
#define isAfterIOS6 ([[[UIDevice currentDevice] systemVersion] intValue]>6)
#define iOS ([[[UIDevice currentDevice] systemVersion] floatValue])
#define isRetina ([[UIScreen mainScreen] scale]==2)
#define iPhone5 ([UIScreen
instancesRespondToSelect
#define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
//拨打电话
#define canTel
#define tel(phoneNumber)
#define telprompt(phoneNumber) ([[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"telprompt:%@",phoneNumber]]])
//打开URL
#define canOpenURL(appScheme) ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:appScheme]])
#define openURL(appScheme) ([[UIApplication sharedApplication] openURL:[NSURL URLWithString:appScheme]])
//判断是否是 ipad
#define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
//判断是否是 ipod
[[UIDevice currentDevice].model isEqualToString:@"iPod touch"]