IOS開發基礎知識--碎片51

1:https關閉證書跟域名的驗證html

    AFSecurityPolicy *securityPolicy = [AFSecurityPolicy defaultPolicy];
    securityPolicy.allowInvalidCertificates = YES;
    securityPolicy.validatesDomainName = NO;
    _manager.securityPolicy = securityPolicy;

若是報 In order to validate a domain name for self signed certificates, you MUST use pinning 也是上面這種方式進行解決ios

2: iOS UIWebView 訪問https繞過證書驗證的方法git

@implementation NSURLRequest (NSURLRequestWithIgnoreSSL)
+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)host
{
    return YES;
}
@end

3:SDWebImage加載圖片繞過證書github

    [myImageView sd_setImageWithURL:[NSURL URLWithString:replyModel.reply_name] placeholderImage:[UIImage imageNamed:@"default_header"]  options:SDWebImageAllowInvalidSSLCertificates]

4:關於Https一些不錯的文章介紹dom

http://oncenote.com/2014/10/21/Security-1-HTTPS/
http://www.jianshu.com/p/2d72ef8dbf5a
http://www.jianshu.com/p/b03ae4a1a2d3
https://github.com/cos6meteors/YMHttpsTest
http://blog.csdn.net/duanbokan/article/details/50847612
http://www.cocoachina.com/ios/20161220/18393.html

5:強制去除HTML標籤的文本iphone

+ (NSString *)getStandarString:(NSString *)str
{
    
    NSArray *components = [str componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
    NSMutableArray *componentsToKeep = [NSMutableArray array];
    
    for (int i = 0; i < [components count]; i = i + 2) {
        
        NSString *str = [components objectAtIndex:i];
        if (str.length) {
            [componentsToKeep addObject:[components objectAtIndex:i]];
        }
        
        
    }
    
    NSString *plainText = [componentsToKeep componentsJoinedByString:@"\n"];
    
    plainText = [[[plainText description]stringByReplacingOccurrencesOfString:@"&nbsp;" withString:@""]stringByReplacingOccurrencesOfString:@" " withString:@""];
    
    return plainText;
    
}

 6: iOS8之後第三方鍵盤,獲取高度爲0的問題ide

IOS8.0以後能夠安裝第三方鍵盤,如搜狗輸入法之類的。
得到的高度都爲0.這是由於鍵盤彈出的方法:- (void)keyBoardWillShow:(NSNotification *)notification須要執行三次,你若是打印一下,你會發現鍵盤高度爲:第一次:0;第二次:216:第三次:282.並非獲取不到高度,而是第三次才獲取真正的高度.
能夠在UIKeyboardDidChangeFrameNotification的通知中實現,這裏須要注意的是:在彈出鍵盤時該方法執行3次,須要進行處理,已達到所要的效果.
註冊鍵盤事件:
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyBoardChange:) name:UIKeyboardDidChangeFrameNotification object:nil];佈局

pragma mark–鍵盤改變事件的觸發ui

(void)keyBoardChange:(NSNotification *)notification{

NSDictionary *dict = notification.userInfo; 
NSValue *aValue = [dict objectForKey:UIKeyboardFrameEndUserInfoKey]; 
NSNumber *animationTime = [dict objectForKey:@」UIKeyboardAnimationDurationUserInfoKey」];

CGRect keyboardRect = [aValue CGRectValue]; 
CGFloat keyHeight = (HEIGHT(self.view)-Y(searBar)-HEIGHT(searBar))-keyboardRect.size.height; 
if(keyHeight<=0){ 
[UIView animateWithDuration:[animationTime doubleValue] animations:^{ 
self.view.frame =CGRectMake(0, keyHeight, WIDTH(self.view), HEIGHT(self.view)); 
} completion:^(BOOL finished) { 
}]; 
}

}

pragma mark–鍵盤隱藏事件spa

(void)keyBoardDidHide:(NSNotification *)notification{ 
self.view.frame = CGRectMake(0, 0, WIDTH(self.view), HEIGHT(self.view)); 
}

 

另有一份代碼:

- (void)keyboardWillShow:(NSNotification *)notification {
 CGFloat curkeyBoardHeight = [[[notification userInfo] objectForKey:@"UIKeyboardBoundsUserInfoKey"] CGRectValue].size.height;
    CGRect begin = [[[notification userInfo] objectForKey:@"UIKeyboardFrameBeginUserInfoKey"] CGRectValue];
    CGRect end = [[[notification userInfo] objectForKey:@"UIKeyboardFrameEndUserInfoKey"] CGRectValue];
    
    // 第三方鍵盤迴調三次問題,監聽僅執行最後一次
    if(begin.size.height>0 && (begin.origin.y-end.origin.y>0)){
        keyBoardHeight = curkeyBoardHeight;
        [self showKeyboard:notification];
    }
}

 

7:UITableView-FDTemplateLayoutCell在IOS10.3中的兼容問題

10.3 系統,Label高度自適應不行了

在cell裏進行佈局以前先對contentView進行約束就能夠了,解決的方式以下:

[self.contentView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self); }];

 

 8: jenkins打包問題

自動打包時一直報:

error: Resource "/Users/jenkins/Library/Developer/Xcode/DerivedData/zxptUser-ekdrtnqmfkdbvqdhibtuhmrvdzhj/Build/Products/Debug-iphoneos/MWPhotoBrowser/MWPhotoBrowser.bundle" not found. Run 'pod install' to update the copy resources script.

解決辦法:

https://github.com/CocoaPods/CocoaPods/issues/5358

如上所說:

in my case, in Jenkins config:

  • SYMROOT must be set
  • BUILD_DIR has no incidence
  • CONFIGURATION_BUILD_DIR must not be set  

而在咱們自動打包的腳本中有一處:

build()
{
    echo "`date` start to build project..."
    cd $WorkSpace
    /usr/local/bin/xctool -workspace Blossom.xcworkspace -scheme Blossom_test CONFIGURATION_BUILD_DIR=$CompileOutputPath #PROVISIONING_PROFILE=$ProvisioningProfile

}

問題所在地方就是:CONFIGURATION_BUILD_DIR

build()
{
    echo "`date` start to build project..."
    cd $WorkSpace
    /usr/local/bin/xctool -workspace Blossom.xcworkspace -scheme Blossom_test SYMROOT=${WORKSPACE}/build #PROVISIONING_PROFILE=$ProvisioningProfile

}

 

9:關於NSDateFormatter的格式

G: 公元時代,例如AD公元
yy: 年的後2位
yyyy: 完全年
MM: 月,顯示爲1-12
MMM: 月,顯示爲英文月份簡寫,如 Jan
MMMM: 月,顯示爲英文月份全稱,如 Janualy
dd: 日,2位數表示,如02
d: 日,1-2位顯示,如 2
EEE: 簡寫星期幾,如Sun
EEEE: 全寫星期幾,如Sunday
aa: 上下午,AM/PM
H: 時,24小時制,0-23
K:時,12小時制,0-11
m: 分,1-2位
mm: 分,2位
s: 秒,1-2位
ss: 秒,2位
S: 毫秒
相關文章
相關標籤/搜索