笔记

  • 数组取值

1.使用 valueForKeyPath

valueForKeyPath 取到所有当前keyvalue值 返回数组

2.使用 谓词提取数据, 可以返回满足条件的model数据

NSNumber *testNumber = @123;
  NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF = 123"];
  if ([predicate evaluateWithObject:testNumber]) {
      NSLog(@"testString:%@", testNumber);
  }

2.1. 姓名过滤

NSArray * nameFilter = [_model.addressList filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"name CONTAINS %@",searchText]];

终端下执行下面命令

显示全部文件
defaults write com.apple.finder AppleShowAllFiles -bool true
osascript -e 'tell application "Finder" to quit'

不显示全部文件
defaults write com.apple.finder AppleShowAllFiles -bool false
osascript -e 'tell application "Finder" to quit'

3.获取微信用户信息

    [[AFHTTPSessionManager manager]
     GET:@"https://api.weixin.qq.com/sns/oauth2/access_token"
     parameters:@{@"appid":KWechatAPPID,
                  @"secret":KWechatAPPSecret,
                  @"code":strOrEmpty(code),
                  @"grant_type":@"authorization_code"}
     progress:^(NSProgress * _Nonnull downloadProgress) {
         
     }
     success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
         
         //解析access_token
         NSLog(@"获取access_token: %@\n openid: %@",[responseObject objectForKey:@"access_token"],[responseObject objectForKey:@"openid"]);
         
         
         //微信登录
         NSString * openId = [responseObject objectForKey:@"openid"];
         
         NSString * access_token = [responseObject objectForKey:@"access_token"];
         //unionid
         NSString *url =[NSString stringWithFormat:@"https://api.weixin.qq.com/sns/userinfo?access_token=%@&openid=%@",access_token,openId];
         dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
             NSURL *zoneUrl = [NSURL URLWithString:url];
             NSString *zoneStr = [NSString stringWithContentsOfURL:zoneUrl encoding:NSUTF8StringEncoding error:nil];
             NSData *data = [zoneStr dataUsingEncoding:NSUTF8StringEncoding];
             dispatch_async(dispatch_get_main_queue(), ^{
                 if (data) {
                     NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
                     
                     [[NSNotificationCenter defaultCenter] postNotificationName:WXLoginSuccessNotification object:dic];
                     
                 }
             });
             
         });
         
     } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
         
         NSLog(@"走到这里面了-===========");
         
         UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"获取用户信息失败" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
         [alertView show];
         
     }];
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容