AFNetworking图像不存储在缓存中?

时间:2013-11-07 13:19:52

标签: ios iphone afnetworking

我使用AFNetworking从PhotoLibaray和相机上传我的服务器上的图像。图像在我的服务器上成功上传。之后还使用AFNetworking获取了所有图像。但是当我获取所有图像时,我从相机上传的图像没有存储在缓存中。只有PhotoLibrary图像存储在缓存中。

使用相机或PhotoLibrary上传图片

-(void)UploadImage
{
     NSString *stringUrl = @"My_Url";

    NSString *User_Id = [[AppDelegate getdefaultvalue] valueForKey:@"User_Id"];

    NSDictionary *parameters = [NSDictionary dictionaryWithObjectsAndKeys:User_Id,@"id",Str_FestName,@"F_Name",Str_FestWeather,@"F_Weather",Str_FestSize,@"F_Size",Str_FestLoc,@"F_Location",Str_FestDate,@"F_Date",Str_FestDisctrpt,@"F_Discription", nil];

    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

    NSLog(@"file path ==%@",[[AppDelegate getdefaultvalue] valueForKey:@"LocalPath_Fest"]);

    if ([[[AppDelegate getdefaultvalue] valueForKey:@"LocalPath_Fest"] length] == 0)
    {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"FestEvo" message:@"Please Select image" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:Nil, nil];
        [alert show];
        [[[AppDelegate sharedinstance] window] setUserInteractionEnabled:YES];
    }
    else
    {

    NSURL *filePath = [NSURL fileURLWithPath:[[AppDelegate getdefaultvalue] valueForKey:@"LocalPath_Fest"]];

    //NSURL *filePath = [[AppDelegate getdefaultvalue] valueForKey:@"LocalPath"];

    NSLog(@"file path ==%@",filePath);

    // NSURL *filePath = [NSURL fileURLWithPath:self.localFilePath];

    [manager POST:stringUrl parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData)
     {
         [formData appendPartWithFileURL:filePath name:@"userfile" error:nil];
     }
     success:^(AFHTTPRequestOperation *operation, id responseObject)
     {

         [MBProgressHUD hideHUDForView:self.view animated:YES];
         [[[AppDelegate sharedinstance] window] setUserInteractionEnabled:YES];
         NSLog(@"Success: %@", responseObject);

         NSString *Resp = [[[[responseObject valueForKey:@"Root"] objectAtIndex:0] valueForKey:@"Record"] valueForKey:@"message"];

         alert_Success = [[UIAlertView alloc]initWithTitle:@"FestEvo" message:Resp delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:Nil, nil];
         [alert_Success show];
     }
     failure:^(AFHTTPRequestOperation *operation, NSError *error)
     {
         [MBProgressHUD hideHUDForView:self.view animated:YES];
         [[[AppDelegate sharedinstance] window] setUserInteractionEnabled:YES];
         NSLog(@"Error: %@", error);
         UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"FestEvo" message:[error localizedDescription] delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:Nil, nil];
         [alert show];
     }];
    }

}

了解所有图像数据

-(void)AllImageData
{

    NSString *stringUrl = @"MY_Url";

    NSURLRequest *UrlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:stringUrl]];

    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]initWithRequest:UrlRequest];

    operation.responseSerializer=[AFJSONResponseSerializer new];

    [operation  setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject)
     {
         [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
         self.Ary_AllFest = [responseObject valueForKey:@"Root"];
         [ArrSearchResult addObjectsFromArray:Ary_AllFest];
         [tblFest_list reloadData];


     }
     failure:^(AFHTTPRequestOperation *operation, NSError *error)
     {
         [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
         UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"FestEvo" message:[error localizedDescription] delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:Nil, nil];
         [alert show];

     }];

    [operation start];


}

在imageview中设置图片

[imageView setImageWithURL:[NSURL URLWithString:[[[self.Ary_AllFest objectAtIndex:indexPath.row] valueForKey:@"Record"] valueForKey:@"image"]];

但只有photoLibary图像存储在缓存中而不是相机图像。

0 个答案:

没有答案