2014-09-25 11 views
5

ilekroć uruchomić tę funkcję, otrzymuję błąd twierdzenia co należy zrobićAssertion w - [AFHTTPRequestSerializer requestWithMethod: URLString: Parametry: error:]

[MBProgressHUD showHUDAddedTo:self.view animated:YES]; 
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; 
    NSString *link = [NSString stringWithFormat:@"%@device_model_no=%@&device_serial_no=%@&device_imei=%@&note=%@&disclaimer=%@&extra_note=%@&package_plan=%@&price=%@&duration=%@&device=%@&user_reg_id=%@&device_category=%@",KURL,txtModelNumber.text,txtSerialNo.text,txtIMEI.text,txtViewExtra.text,deviceDisclamer,additonalDetail.text,plan,price,duration,deviceName,userID,nil]; 
    NSLog(@"%@",link); 

    manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"]; 

    [manager GET:link parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) { 
     NSLog(@"JSON: %@", responseObject); 


     NSLog(@"%@", responseObject); 

     NSDictionary *returnedDealDict = responseObject ; 
     NSArray *returnArray = [returnedDealDict objectForKey:@"result"]; 

     for(NSDictionary *dealDict in returnArray) 
     { 
      if ([dealDict objectForKey:@"success"]) 
      { 
       ALERT_VIEW(@"Thanks1! Your information has been saved Successfully! We will contact you soon.") 
      } 
      else 
      { 
       ALERT_VIEW(@"Your information doesn t exist in our database, Please go back and enter your contact info again!") 
      } 
     } 
     success(); 

     [MBProgressHUD hideHUDForView:self.view animated:YES]; 




    } 
     failure:^(AFHTTPRequestOperation *operation, NSError *error) { 
      NSLog(@"Error: %@", error); 
      ALERT_VIEW(@"Error occured while loading data."); 
      NSLog(@"getBrandDevice Error"); 
      [MBPro 

gressHUD hideHUDForView:self.view animated:YES]; 
      }]; 

otrzymuję ten błąd

** Assertion failure in -[AFHTTPRequestSerializer requestWithMethod:URLString:parameters:error:], /Users/ios2/Desktop/untitled folder/PhablatFIx/PhablatFIx/MVC/Model/AFNetworking/AFURLRequestSerialization.m:277 
    2014-09-25 10:33:26.733 PhablatFIx[721:90b] 

* Kończenie aplikacji z powodu nieprzechwyconego wyjątku "NSInternalInconsistencyException", powód: "Niepoprawny parametr nie jest satysfakcjonujący: URLString" * Pierwszy stos wywoławczy:

+0

Co czy adres URL się kończy? – borrrden

Odpowiedz

21

trzeba dodać poniższy wiersz kodu w celu uniknięcia Nieprawidłowy parametr String url

NSString *encoded = [link stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 
+0

działa idealnie –

+0

Działa jak rakieta! – Abo3atef

+1

Praca jak rakieta –

3
  • (nullable NSString *)stringByAddingPercentEscapesUsingEncoding:(NSStringEncoding)enc NS_DEPRECATED(10_0, 10_11, 2_0, 9_0, "Use -stringByAddingPercentEncodingWithAllowedCharacters: instead, which always uses the recommended UTF-8 encoding, and which encodes for a specific URL component or subcomponent since each URL component or subcomponent has different rules for what characters are valid.");

@NullData odpowiedzieć pracy doskonale w tej chwili, ale metoda stringByAddingPercentEscapesUsingEncoding jest przestarzała tak, chłopaki powinni rozważyć zamiast tego użyj metody stringByAddingPercentEncodingWithAllowedCharacters.

tak dla szybkiego

let path = myurlstring.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet()) 

czy to dla ObjC

path = [path stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]; 
2

maja adres URL jest nieprawidłowy, istnieją przestrzenie, błędnych znaków, itp na przykład: enter image description here