zoukankan      html  css  js  c++  java
  • 新浪微博客户端(40)-使用AFN发送带图片的微博

    DJComposeViewController.m

    /** 发微博 */
    - (void)sendStatusRequest {
    
        AFHTTPSessionManager *RequestManager = [AFHTTPSessionManager manager];
        
        NSArray *photos = self.photosView.photos;
        if (photos.count) { // 当前用户选择了图片
            
            UIImage *photoImage = [photos firstObject];
            NSString *urlString = @"https://upload.api.weibo.com/2/statuses/upload.json";
            NSMutableDictionary *params = [NSMutableDictionary dictionary];
            params[@"access_token"] = [DJAccountTool account].access_token;
            params[@"status"] = self.textView.text;
            
            [RequestManager POST:urlString parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
                [formData appendPartWithFileData:UIImageJPEGRepresentation(photoImage, 1.0) name:@"pic" fileName:@"upload.jg" mimeType:@"image/jpeg"];
            } progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                [MBProgressHUD showSuccess:@"发送成功"];
            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                [MBProgressHUD showError:@"发送失败"];
            }];
            
            
        } else { // 当前用户未选择图片
            
            NSString *urlString = @"https://api.weibo.com/2/statuses/update.json";
            
            NSMutableDictionary *params = [NSMutableDictionary dictionary];
            params[@"access_token"] = [DJAccountTool account].access_token;
            params[@"status"] = self.textView.text;
            
            [RequestManager POST:urlString parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                [MBProgressHUD showSuccess:@"发送成功"];
            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                [MBProgressHUD showError:@"发送失败"];
            }];
        
        }
        
        // 关闭当前界面
        [self dismissViewControllerAnimated:YES completion:nil];
    }

    最终效果:

      

  • 相关阅读:
    django 查询
    django orm
    django 基础
    RFS自动化测试工具安装与使用总结
    虚拟机安装(Cent OS)
    RobotFramework 切换窗口控制的用法小结
    Selenium2Library中select frame关键字对没有name和id的frame或者iframe的处理
    robotframework+selenium2library之上传本地文件
    element not visible的解决方法
    robotframework悬浮菜单定位问题
  • 原文地址:https://www.cnblogs.com/yongdaimi/p/6105197.html
Copyright © 2011-2022 走看看