码迷,mamicode.com
首页 > 微信 > 详细

iOS开发——项目实战总结&类微信朋友圈发动态功能初步-图片与文字篇

时间:2015-11-22 01:32:39      阅读:423      评论:0      收藏:0      [点我收藏+]

标签:

 

类微信朋友圈发动态功能初步-图片与文字篇

 

 1 /**
 2  * 发布带有图片的微博
 3  */
 4 - (void)sendWithImage
 5 {
 6     // URL: https://upload.api.weibo.com/2/statuses/upload.json
 7     // 参数:
 8     /**    status true string 要发布的微博文本内容,必须做URLencode,内容不超过140个汉字。*/
 9     /**    access_token true string*/
10     /**    pic true binary 微博的配图。*/
11     
12     // 1.请求管理者
13     AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager];
14     
15     // 2.拼接请求参数
16     NSMutableDictionary *params = [NSMutableDictionary dictionary];
17     params[@"access_token"] = [HWAccountTool account].access_token;
18     params[@"status"] = self.textView.fullText;
19     
20     // 3.发送请求
21     [mgr POST:@"https://upload.api.weibo.com/2/statuses/upload.json" parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
22         // 拼接文件数据
23         UIImage *image = [self.photosView.photos firstObject];
24         NSData *data = UIImageJPEGRepresentation(image, 1.0);
25         [formData appendPartWithFileData:data name:@"pic" fileName:@"test.jpg" mimeType:@"image/jpeg"];
26     } success:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject) {
27         [MBProgressHUD showSuccess:@"发送成功"];
28     } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
29         [MBProgressHUD showError:@"发送失败"];
30     }];
31 }
32 
33 /**
34  * 发布没有图片的微博
35  */
36 - (void)sendWithoutImage
37 {
38     // URL: https://api.weibo.com/2/statuses/update.json
39     // 参数:
40     /**    status true string 要发布的微博文本内容,必须做URLencode,内容不超过140个汉字。*/
41     /**    access_token true string*/
42     // 1.请求管理者
43     AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager];
44     
45     // 2.拼接请求参数
46     NSMutableDictionary *params = [NSMutableDictionary dictionary];
47     params[@"access_token"] = [HWAccountTool account].access_token;
48     params[@"status"] = self.textView.fullText;
49     
50     // 3.发送请求
51     [mgr POST:@"https://api.weibo.com/2/statuses/update.json" parameters:params success:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject) {
52         [MBProgressHUD showSuccess:@"发送成功"];
53     } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
54         [MBProgressHUD showError:@"发送失败"];
55     }];
56 }

 

iOS开发——项目实战总结&类微信朋友圈发动态功能初步-图片与文字篇

标签:

原文地址:http://www.cnblogs.com/iCocos/p/4985159.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!