Ios 连接是使用iPhone 5s中的afnetworking进行无文件上传

Ios 连接是使用iPhone 5s中的afnetworking进行无文件上传,ios,iphone,ios7,afnetworking-2,Ios,Iphone,Ios7,Afnetworking 2,我在应用程序中使用afnetworkin上传文件。它在iPhone4上工作,但在iPhone5s上失败 我在上传时获得连接==nil 代码: -(void) uploadFile:(NSURL *)url withFileName:(NSString *)filename mimeType:(NSString *)mimeType { HUD = [[MBProgressHUD alloc] initWithWindow:[UIApplication sharedApplication

我在应用程序中使用afnetworkin上传文件。它在iPhone4上工作,但在iPhone5s上失败

我在上传时获得连接==nil

代码:

-(void) uploadFile:(NSURL *)url withFileName:(NSString *)filename mimeType:(NSString *)mimeType {

    HUD = [[MBProgressHUD alloc] initWithWindow:[UIApplication sharedApplication].keyWindow];
    [self.navigationController.view addSubview:HUD];

    // Set determinate mode
    HUD.mode = MBProgressHUDModeAnnularDeterminate;

    HUD.delegate = self;
    HUD.labelText = @"Uploading";

    progress = 0.0f;

    [HUD showAnimated:YES whileExecutingBlock:^{

        while (progress < 100) {
            //progress += 0.01f;
            HUD.progress = (float)progress/100.0;
            usleep(50000);
        }

    }];


    // 1. Create `AFHTTPRequestSerializer` which will create your request.
    AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer];


    NSError *__autoreleasing *error = NULL;

    // 2. Create an `NSMutableURLRequest`.
    NSMutableURLRequest *request =
    [serializer multipartFormRequestWithMethod:@"POST" URLString:kUploadAPI
                                    parameters:nil
                     constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
                         [formData appendPartWithFileURL:url
                                                    name:@"uploadedfile"
                                                fileName:filename
                                                mimeType:mimeType error:nil];

                     } error:error];

    // 3. Create and use `AFHTTPRequestOperationManager` to create an `AFHTTPRequestOperation` from the `NSMutableURLRequest` that we just created.
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

    operation = [manager HTTPRequestOperationWithRequest:request
                                     success:^(AFHTTPRequestOperation *operation, id responseObject) {

                                         [HUD hide:YES];

                                         // handle response

                                     } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                                         [HUD hide:YES];
                                         NSLog(@"Failure %@", error.description);
                                     }];

    // 4. Set the progress block of the operation.
    [operation setUploadProgressBlock:^(NSUInteger __unused bytesWritten,
                                        long long totalBytesWritten,
                                        long long totalBytesExpectedToWrite) {
        //NSLog(@"Wrote %lld/%lld", totalBytesWritten, totalBytesExpectedToWrite);

        progress = (int)(((float)totalBytesWritten / totalBytesExpectedToWrite) * 100.0);

        NSLog(@"Uploading...%d",(int)progress);

    }];

    // 5. Begin!
    [operation start];

}
使用NSUrlConnection获取委托方法中的错误

- (void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite
{
    ///here I'm getting connection == nil
}

你能找到解决办法吗?我遇到了同样的问题在我的案例中,PonyDebugger引起了一个问题。我删除了PonyDebugger,然后它就工作了。我删除了-voidconnection:NSURLConnection\uuu unused*连接didSendBody数据:nsIntegerBytesWrite TotalBytesWrite:nsIntegerTotalBytesWrite totalBytesExpectedToWrite:NSIntegertotalBytesExpectedToWrite for temparary
- (void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite
{
    ///here I'm getting connection == nil
}