简体   繁体   中英

Sending file using AFNetworking and iOS8

I want to move a subview of my view without deactivating Auto layout, which is useful in other parts of my app.

I was using this code in iOS 7 which was working fine, but is now broken with iOS 8:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    self.avatar = [info objectForKey:UIImagePickerControllerOriginalImage];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    NSString* request = @"/users/";
    [manager
     POST:request parameters: nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
         [formData
              appendPartWithFileData: UIImageJPEGRepresentation(self.avatar, 1.0)
              name: @"picture"
              fileName: @"new_avatar.jpg"
              mimeType: @"image/jpeg"
         ];
     } success:^(AFHTTPRequestOperation *operation, id responseObject) {
     } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
         NSLog(@"Could not send picture %@ !", error);
     }];

I don't understand what is going on, UIImageJPEGRepresentation(self.avatar, 1.0) contains the image, and as I said, everything was working fine with iOS7.

No request is even made to the server...

您是否为iOS 8升级了AFNetwork lib。因为我遇到了同样的问题,但是升级后,一切都恢复了正常。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM