日常开发问题记录

279 阅读1分钟

新公司做个商城组件,pod lib lint各种奇怪报错

s.pod_target_xcconfig = {'VALID_ARCHS'=>'x86_64 armv7 arm64'}

post参数问题,直接按postman请求成功后的复制代码方式不行,得换成下面这种,后台才不会报参数错误

/// post参数拼接成串
static inline NSString *strFromParams(NSDictionary *params) {
    NSMutableString *muStr = [NSMutableString string];
    [params enumerateKeysAndObjectsUsingBlock:^(id  _Nonnull key, id  _Nonnull obj, BOOL * _Nonnull stop) {
        [muStr appendString:[NSString stringWithFormat:@"%@=%@",key,[params objectForKey:key]]];
        [muStr appendString:@"&"];
    }];
    // 去除最后一个 &
    [muStr replaceCharactersInRange:NSMakeRange(muStr.length-1, 1) withString:@""];
    return muStr;
}

添加的事件不响应 -> 别写在let属性里,控件被添加到父控件后再添加事件代码


约束布局下圆角失效->处理圆角放layoutSubviews里,


override func layoutSubviews() {
        super.layoutSubviews()
        addTopLeftAndTopRightCorner(35)
    }
private func addTopLeftAndTopRightCorner(_ corner:CGFloat) {
        if (self.layer.mask != nil) {
            return
        }
        let f = self.bounds
        let path = UIBezierPath(roundedRect: f, byRoundingCorners: [.topLeft, .topRight], cornerRadii: CGSize(width: corner, height: corner))
        let layer =  CAShapeLayer()
        layer.frame = f
        layer.path = path.cgPath
        self.layer.mask = layer
    }


http接口请求,wkwebview访问http url

1、info.plist里

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>yourdomain.com</key>
        <dict>
            <key>NSExceptionAllowInsecureHTTPLoads</key>
            <true/>
            <key>NSExceptionRequiresForwardSecrecy</key>
            <true/>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
            <true/>
        </dict>
    </dict>
    <key>NSAllowsArbitraryLoadsInWebContent</key>
    <true/>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

2、wkwebview vc 追加方法

- (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential * _Nullable credential))completionHandler{
    
    if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
        
        NSURLCredential *card = [[NSURLCredential alloc]initWithTrust:challenge.protectionSpace.serverTrust];
        
        completionHandler(NSURLSessionAuthChallengeUseCredential,card);
        
    }
}