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];
    }

    最终效果:

      

  • 相关阅读:
    Python 面向对象(下)
    Python 面向对象(上)
    《面向对象程序设计概述》 牛咏梅
    lastIndexOf is not a function
    oracle lpad 函数使用介绍
    oracle中length、lengthb、substr、substrb用法小结
    oracle获取字符串长度函数length()和hengthb()
    js获取当前日期时间
    win7系统下查看端口的占用情况以及如何删除端口进程
    IntelliJ IDEA “Finds duplicated code”提示如何关闭
  • 原文地址:https://www.cnblogs.com/yongdaimi/p/6105197.html
Copyright © 2011-2022 走看看