
此ios应用程序将一张照片发送到博客.
我无法弄清楚图像无法加载的原因.
这是我到目前为止所得到的:
// publish text and image-(voID)publishTextAndImage:(Nsstring*)resultdisplay and:(Nsstring*)subject with:(Nsstring*)nonce{imageData = UIImageJPEGRepresentation(selectedImage,0.7); // create a data object from selected imageNsstring *myUUID = [[NSUUID UUID] UUIDString]; // create a UUIDNsstring *formatString = [Nsstring stringWithFormat:@"<img src=\"/wp-content/uploads/%@\"/>",myUUID];Nsstring *contentString = [formatString stringByAppendingString:resultdisplay];Nsstring *moodString = [Nsstring stringWithFormat:@"%d",self.moodNumber];NSDictionary *parameters = @{@"Title":subject,@"content":contentString,@"status":@"publish",@"author":@"wordpress",@"user_password":@"xrayyankee",@"nonce":nonce,@"categorIEs":moodString,@"attachment":@"image/jpeg"}; AFhttpRequestoperationManager *manager = [AFhttpRequestoperationManager manager];[manager POST:@"http://thrills.it/?Json=posts/create_post" parameters:parameters constructingBodyWithBlock:^(ID<AFMultipartFormData> formData) { if (selectedImage) { [formData appendPartWithfileData:imageData name:@"photo" filename:myUUID mimeType:@"image/jpeg"]; } } success:^(AFhttpRequestoperation *operation,ID responSEObject) { NSLog(@"JsON: %@",responSEObject); } failure:^(AFhttpRequestoperation *operation,NSError *error) { NSLog(@"Error: %@",error); }]; }
谢谢你们
解决方法 我用这种方式使用AFNetworking:AFhttpClIEnt *clIEnt = [[AFhttpClIEnt alloc] initWithBaseURL:[NSURL URLWithString:@"http://thrills.it/?Json=posts"]];NSURLRequest *request = [clIEnt multipartFormRequestWithMethod:@"POST" path:@"create_post" parameters:parameters constructingBodyWithBlock:^(ID<AFMultipartFormData> formData){ if (selectedImage) { [formData appendPartWithfileData:imageData name:@"photo" filename:myUUID mimeType:@"image/jpeg"]; }} ];AFJsONRequestoperation *operation = [AFJsONRequestoperation JsONRequestoperationWithRequest:request success:^(NSURLRequest *request,NShttpURLResponse *response,ID JsON) { NSLog(@"JsON: %@",responSEObject);} failure:^(NSURLRequest *request,NSError *error,ID JsON) { NSLog(@"Error: %@",error);}];[operation setUploadProgressBlock:^(NSUInteger bytesWritten,long long totalBytesWritten,long long totalBytesExpectedToWrite) { float progressValue = (float)((double)totalBytesWritten/(double)totalBytesExpectedToWrite); NSLog(@"%f",progressValue);}];[self.queue addOperation:operation]; .
@property (nonatomic,strong) NSOperationQueue *queue;
我的客户端是先前创建的,但它是这样创建的.
我希望这会有所帮助.
总结以上是内存溢出为你收集整理的ios – 使用AFNetworking 2.0加载图像全部内容,希望文章能够帮你解决ios – 使用AFNetworking 2.0加载图像所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)