2014.8.2 凌晨起退伍啦!
看來 blogger 的標題也要想個新名字!
2014年8月28日 星期四
[iOS] Switching from http to https. Invalid certificate
常用一些第三方套件提供網路通訊時,如果 server 端為 https 需要做一些設定來排除如標題所提到的問題,主要是設定允許 certificate 存取:
@interface NSURLRequest(Private)
+(void)setAllowsAnyHTTPSCertificate:(BOOL)inAllow forHost:(NSString *)inHost;
@end
使用如下指令:
[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[inURL host]];
如果是使用 AFNetworking 套件時再加入以下定義:(加在 .pch 檔內)
#ifdef DEBUG
#define _AFNETWORKING_ALLOW_INVALID_SSL_CERTIFICATES_
#endif
參考來源:http://stackoverflow.com/questions/12447318/switching-from-http-to-https-invalid-certificate
@interface NSURLRequest(Private)
+(void)setAllowsAnyHTTPSCertificate:(BOOL)inAllow forHost:(NSString *)inHost;
@end
使用如下指令:
[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[inURL host]];
如果是使用 AFNetworking 套件時再加入以下定義:(加在 .pch 檔內)
#ifdef DEBUG
#define _AFNETWORKING_ALLOW_INVALID_SSL_CERTIFICATES_
#endif
參考來源:http://stackoverflow.com/questions/12447318/switching-from-http-to-https-invalid-certificate
[iOS] NSTimer 機制小記
常常在用 NSTimer 來設計一些延遲或重覆執行某個 func call,但如果有用到 touch 事件,如:圖片點擊,UIScrollView 滑動等,就會把該 fund call 暫停,直到 touch 結束才繼續執行。
這樣一來就有時間差的問題存在,問了 google 大大後得知有人分享解決方式,就是將 NSTimer 加到別的 RunLoopMode 即可。
在 NSTimer 初始化後加入以下指令:
[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
參考來源:http://stackoverflow.com/questions/6684016/why-timer-stops-when-scrolling-in-uiwebview-iphone
這樣一來就有時間差的問題存在,問了 google 大大後得知有人分享解決方式,就是將 NSTimer 加到別的 RunLoopMode 即可。
在 NSTimer 初始化後加入以下指令:
[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
參考來源:http://stackoverflow.com/questions/6684016/why-timer-stops-when-scrolling-in-uiwebview-iphone
2014年8月19日 星期二
[iOS] 畫個虛線
- (void)makeLineInImageView:(UIImageView *)imageView
{
UIGraphicsBeginImageContext(imageView.frame.size);
[imageView.image drawInRect:CGRectMake(0, 0, imageView.frame.size.width, imageView.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); //設定線條終點形狀
float lengths[] = {2, 2}; //第一個參數設定每個虛線寬度,第二個參數設定虛線的間隔
CGContextRef line = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(line, [UIColor grayColor].CGColor);
CGContextSetLineDash(line, 0, lengths, 2);
CGContextMoveToPoint(line, 0.0f, 0.0f); //開始畫線
CGContextAddLineToPoint(line, imageView.frame.size.width, 0.0f);
CGContextStrokePath(line);
imageView.image = UIGraphicsGetImageFromCurrentImageContext();
}
{
UIGraphicsBeginImageContext(imageView.frame.size);
[imageView.image drawInRect:CGRectMake(0, 0, imageView.frame.size.width, imageView.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); //設定線條終點形狀
float lengths[] = {2, 2}; //第一個參數設定每個虛線寬度,第二個參數設定虛線的間隔
CGContextRef line = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(line, [UIColor grayColor].CGColor);
CGContextSetLineDash(line, 0, lengths, 2);
CGContextMoveToPoint(line, 0.0f, 0.0f); //開始畫線
CGContextAddLineToPoint(line, imageView.frame.size.width, 0.0f);
CGContextStrokePath(line);
imageView.image = UIGraphicsGetImageFromCurrentImageContext();
}
訂閱:
文章 (Atom)