企业开发证书 Hoc 和in house区别
// 最后需要移除监听
[[NSNotificationCenter defaultCenter] removeObserver:self.observer];
#####一次性通知(监听1次后就不再监听)
```python
id observer = [[NSNotificationCenter defaultCenter] addObserverForName:UITextFieldTextDidBeginEditingNotification object:self queue:[[NSOperationQueue alloc] init] usingBlock:^(NSNotification * _Nonnull note) {
// 移除通知
[[NSNotificationCenter defaultCenter] removeObserver:observer];
}];
线程
- 如果在线程A发出通知,那么就会在线程A中接收通知
dispatch_async(dispatch_get_global_queue(0, 0), ^{
// 系统会在子线程中处理test这个通知
[[NSNotificationCenter defaultCenter] postNotificationName:@"test" object:nil];
});
利用 SDWebImage 设置 UIButton 的图片
[button sd_setImageWithURL:[NSURL URLWithString:url] forState:UIControlStateNormal placeholderImage:image];
查找字符串的常见方法
// 如果range.location == 0, 说明是以searchString开头
// 如果range.location == NSNotFound或者range.length == 0, 说明没找到对应的字符串
- (NSRange)rangeOfString:(NSString *)searchString;
// 是否以str开头
- (BOOL)hasPrefix:(NSString *)str;
// 是否以str结尾
- (BOOL)hasSuffix:(NSString *)str;
// 是否包含了str(不管头部\中间\尾部)
- (BOOL)containsString:(NSString *)str;
判断NSString字符串或NSArray数组是否为空
条件判断的一些注意点
1.判断一个数组中是否有具体内容
1> 正确
if (array.count) {
}
2> 错误
if (array) {
}
2.判断一个字符串是否有具体内容
1> 正确
if (string.length) {
}
2> 错误
if (string) {
}
判断NSString字符串的最佳方法
#pragma mark ======ios 判断字符串为空和只为空格解决办法==
/**
* @author MISSAJJ, 15-11-25
*/
+ (BOOL)isBlankString:(NSString *)string{
//字符串的长度为0表示空串
if (string.length == 0) {
return YES;
}
if (string == nil) {
return YES;
}
if (string == NULL) {
return YES;
}
if ([string isEqualToString:@""]) {
return YES;
}
if ([string isKindOfClass:[NSNull class]]) {
return YES;
}
if ([[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length]==0) {
return YES;
}
return NO;
}
判断数组为空的最佳方法
- ios 判断数组为空的解决办法
+ (BOOL)isBlankArray:(NSArray *)array{
if (array == nil) {
return YES;
}
if ([array isKindOfClass:[NSNull class]]) {
return YES;
}
if (array.count == 0) {
return YES;
}
return NO;
}
证书SSL问题
此服务器的证书无效。您可能正在连接到一个伪装成“xxx.com”的服务器。这会威胁到您的机密信息的安全 或者SSL证书安全问题
服务器配置的证书不对,苹果要求是TLS1.2以上 服务端配置是TLS1.0。
改变指定文字颜色大小
_searchLabel.text = [NSString stringWithFormat:@"未找到'%@'相关结果", searchName];
NSRange rangeRmb = [_searchLabel.text rangeOfString:searchName];
NSMutableAttributedString * rmbStr = [[NSMutableAttributedString alloc] initWithString:_searchLabel.text attributes:nil];
NSDictionary * fontDic = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor], NSForegroundColorAttributeName, [UIFont systemFontOfSize:17], NSFontAttributeName, nil];
[rmbStr addAttributes:fontDic range:rangeRmb];
_searchLabel.attributedText = rmbStr;
+ (void)PUT:(NSString *)URLString data:(NSData *)data parameters(NSDictionary *)parameters progress:(HttpProgress)progress success:(HttpRequestSuccess)success failure:(HttpRequestFailed)failure {
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
NSMutableURLRequest *request = [[AFJSONRequestSerializer serializer] multipartFormRequestWithMethod:@"PUT" URLString:URLString parameters:nil
constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
if (data) {
[formData appendPartWithFileData:data name:@"file" fileName:@"data.txt" mimeType:@"multipart/form-data"];
}
} error:nil];
if (parameters && parameters.count > 0) {
[request setHTTPBody:[NSJSONSerialization dataWithJSONObject:parameters options:NSJSONWritingPrettyPrinted error:nil]];
}
__block NSURLSessionDataTask *task;
task = [manager uploadTaskWithStreamedRequest:request progress:^(NSProgress * _Nonnull uploadProgress) {
} completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
}];
[task resume];
}
1.打开常亮
[ [ UIApplication sharedApplication] setIdleTimerDisabled:YES] ;
2.关闭长亮
[ [ UIApplication sharedApplication] setIdleTimerDisabled:NO] ;
iOS11 HTTP load failed (error code: -999)
对AFN中的参数设置, 允许不进行证书验证
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
//无条件的信任服务器上的证书
AFSecurityPolicy *securityPolicy = [AFSecurityPolicy defaultPolicy];
// 客户端是否信任非法证书
securityPolicy.allowInvalidCertificates = YES;
// 是否在证书域字段中验证域名
securityPolicy.validatesDomainName = NO;
manager.securityPolicy = securityPolicy;
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section 代理方法不走的原因 解决:
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section 设置高度方法 高度不能为0 否则不走代理方法
图片比例约束
- (void)viewDidLoad {
UIView *topView = [UIView new];
topView.backgroundColor = [UIColor redColor];
[self.view addSubview:topView];
UIView *topInnerView = [UIView new];
topInnerView.backgroundColor = [UIColor greenColor];
[topView addSubview:topInnerView];
//设置约束
[topView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(20);
make.right.mas_equalTo(-20);
make.top.mas_equalTo(100);
make.height.mas_equalTo(100);
}];
[topInnerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(topView);
// make.width.mas_equalTo(topView);
// make.height.mas_equalTo(topView.mas_height).multipliedBy(0.5);
//设置宽高比例为7:1
make.width.mas_equalTo(topInnerView.mas_height).multipliedBy(7);
make.center.mas_equalTo(topView);
//设置优先级
make.width.height.mas_equalTo(topView).priorityLow();
make.width.height.lessThanOrEqualTo(topView);
}];
}
为什么block修饰用copy 不用strong?
MRC:Block的内存地址显示在栈区,栈区的特点就是创建的对象随时可能被销毁,一旦被销毁后续再次调用空对象就可能会造成程序崩溃,在对block进行copy后,block存放在堆区.所以在使用Block属性时使用copy修饰。但是ARC中的Block都会在堆上的,系统会默认对Block进行copy操作
### 声明类型为NSArray的属性时,使用copy修饰
防止类型被修改
防止值被修改
声明类型为NSMutableArray的属性时,使用strong修饰
防止类型被修改,从而造成crash
UINavigation 去线
[navBar setBackgroundImage:[UIImage imageWithColor:KWhiteColor] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
[navBar setShadowImage:[[UIImage alloc] init]];