加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

IOS - 常用开发Tips(二公共适配部分常用宏)

(2014-03-01 17:45:56)
标签:

ios-常用开发tip

it

分类: Mac/IOS那些事
1. Apple 检测是否使用的私有API,并不会真正去跑你的程序,而是通过可执行文件检查关键字。
检测的方法大概有三种:
ottool -l ; 这个方法可以列出你的二进制可执行文件所link的所有的libraries,如果你link了类似WebKit这类的东西,那说明你肯定使用了私有API。
nm -u  ; 这个方法可以列出所有的link 符号。包括没有在文档中出现过的C方法,一些特殊的Objc类( UIProgressHUD),还有一些变量(UITouch._phase)等。
最后一个可以猜到的方法:由于objc的方法存储在你的可执行文件的一个固定的区域,Apple绝对有工具把那块区域的内容直接翻译成文本并检查所有的方法中有没有私有API方法。

2 . runtime提供的功能确实强大,但是你真的要使用私有API,还是有风险的,苹果还有运行时的沙盒测试,把你的程序   跑一下,只要有任何企图接触沙盒外部的尝试,都会被干掉。

  但是我估计第二个并不是对每个程序都使用。
以上都来源于我长期的实践和网络上的资料, 没有任何官方文档说明,仅作参考。
我曾经在代码中使用过runtime来替换系统框架的某个方法来达到实现自己的目的,程序没有被拒绝。
我也曾经在一个完整的使用公开API的程序中,尝试加入了一个对私有API的引用(不使用它的任何方法),程序直接被拒,原因就是使用了私有API。
来源链接 http://www.cocoachina.com/bbs/simple/?t67044.html

3 如果在iphone5以上的版本 编译出来的依然是 320x480的屏幕 
  进入 Gerneral 设置 appicons 跟 lanuch images 当然了事ios7下得尺寸 
4 使用Images.xcassets 需要在右侧栏里面的设置适配iPhone 要不然不会自动取2倍的图 
5 适配 iphone 4 跟 5 的屏幕高度,跟定位的时候需要 
     if ( IOS7 )

    {

        self.edgesForExtendedLayout = UIRectEdgeNone;

        self.extendedLayoutIncludesOpaqueBars = NO;

        self.modalPresentationCapturesStatusBarAppearance = NO;

        self.automaticallyAdjustsScrollViewInsets = NO;

    }

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 instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)


 

#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  (^IDBlock)  ();


typedef void(^VoidBlock_int)(int);

typedef BOOL(^BoolBlock_int)(int);

typedef int (^IntBlock_int) (int);

typedef id  (^IDBlock_int)  (int);


typedef void(^VoidBlock_string)(NSString*);

typedef BOOL(^BoolBlock_string)(NSString*);

typedef int (^IntBlock_string) (NSString*);

typedef id  (^IDBlock_string)  (NSString*);


typedef void(^VoidBlock_id)(id);

typedef BOOL(^BoolBlock_id)(id);

typedef int (^IntBlock_id) (id);

typedef id  (^IDBlock_id)  (id);



//System

#define PasteString(string)   [[UIPasteboard generalPasteboard] setString:string];

#define PasteImage(image)     [[UIPasteboard generalPasteboard] setImage:image];



//Image

//可拉伸的图片


#define ResizableImage(name,top,left,bottom,right) [[UIImage imageNamed:name] resizableImageWithCapInsets:UIEdgeInsetsMake(top,left,bottom,right)]

#define ResizableImageWithMode(name,top,left,bottom,right,mode) [[UIImage imageNamed:name] resizableImageWithCapInsets:UIEdgeInsetsMake(top,left,bottom,right) resizingMode:mode]


//file

//读取文件的文本内容,默认编码为UTF-8

#define FileString(name,ext)            [[NSString alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:(name) ofType:(ext)] encoding:NSUTF8StringEncoding error:nil]

#define FileDictionary(name,ext)        [[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:(name) ofType:(ext)]]

#define FileArray(name,ext)             [[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:(name) ofType:(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)  NSLog(@"%@",b?@"YES":@"NO");

//弹出信息

#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)             [UIColor colorWithRed:((r) / 255.0) green:((g) / 255.0) blue:((b) / 255.0) alpha:1.0]

#define RGBAlpha(r, g, b, a)     [UIColor colorWithRed:((r) / 255.0) green:((g) / 255.0) blue:((b) / 255.0) alpha:(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 dateWithTimeIntervalSince1970:[stamp intValue]];




//设备屏幕尺寸

#define kScreen_Height   ([UIScreen mainScreen].bounds.size.height)

#define kScreen_Width    ([UIScreen mainScreen].bounds.size.width)

#define kScreen_Frame    (CGRectMake(0, 0 ,kScreen_Width,kScreen_Height))

#define kScreen_CenterX  kScreen_Width/2

#define kScreen_CenterY  kScreen_Height/2



//应用尺寸(不包括状态栏,通话时状态栏高度不是20,所以需要知道具体尺寸)

#define kContent_Height   ([UIScreen mainScreen].applicationFrame.size.height)

#define kContent_Width    ([UIScreen mainScreen].applicationFrame.size.width)

#define kContent_Frame    (CGRectMake(0, 0 ,kContent_Width,kContent_Height))

#define kContent_CenterX  kContent_Width/2

#define kContent_CenterY  kContent_Height/2




 

#define kP1 CGPointMake(0                 ,0)

#define kP2 CGPointMake(kContent_Width/2  ,0)

#define kP3 CGPointMake(kContent_Width    ,0)

#define kP4 CGPointMake(0                 ,kContent_Height/2)

#define kP5 CGPointMake(kContent_Width/2  ,kContent_Height/2)

#define kP6 CGPointMake(kContent_Width    ,kContent_Height/2)

#define kP7 CGPointMake(0                 ,kContent_Height)

#define kP8 CGPointMake(kContent_Width/2  ,kContent_Height)

#define kP9 CGPointMake(kContent_Width    ,kContent_Height)


//*********************************************



//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 instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)

#define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)



//拨打电话

#define canTel                 ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"tel:"]])

#define tel(phoneNumber)       ([[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"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"]



0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有