iphone - Anonymous response during service consumption iOS -


i facing anonymous behavior of service response. sometime service fetched , gives error message "a server specified host name can't found". using afnetworking. same service worked in android platform. there better way fetch them accurately in iphone.

here piece of code:

dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_high, 0), ^{                  nsdictionary *params = @{@"email"     : txtemail.text,                                          @"password"    : txtpassword.text,                                          };                 afhttprequestoperationmanager *operationmanager = [afhttprequestoperationmanager manager];                 operationmanager.requestserializer = [afjsonrequestserializer serializer];                 operationmanager.responseserializer = [afjsonresponseserializer serializer];                 [operationmanager post:@"http://somelink/someuser.svc/login" parameters:params success:^(afhttprequestoperation *operation, id responseobject) {                     nslog(@"json: %@", operation.responsestring);                     nsdictionary *responsedict = responseobject;                     nslog(@"%@",[responsedict valueforkey:@"result_code"]);                     if ([[responsedict valueforkey:@"result_code"] isequaltostring:@"1"]) {                         nsdictionary *data = [responseobject objectforkey:@"result_data"];                         nslog(@"%@",[data objectforkey:@"email"]);                           [[nsuserdefaults standarduserdefaults]setobject:[data objectforkey:@"user_id"] forkey:@"userid"];                         nsstring *query = [nsstring stringwithformat:@"insert usermaster (user_id, name_first, name_last, email, password, image, gender, rec_limit, total_followers, total_following, is_brand, category) values ('%@','%@','%@','%@','%@','%@','%@',%d,'%@','%@',%d,%d)",[data objectforkey:@"user_id"],[data objectforkey:@"name_first"],[data objectforkey:@"name_last"],[data objectforkey:@"email"],[data objectforkey:@"password"],[data objectforkey:@"image"],[data objectforkey:@"gender"],[[data objectforkey:@"rec_limit"]intvalue],[data objectforkey:@"total_followers"],[data objectforkey:@"total_following"],[[data objectforkey:@"is_brand"]intvalue],[[data objectforkey:@"category"]intvalue]];                          //                    nslog(@"%@",[data objectforkey:@"intrests"]);                           nslog(@"%@",query);                         int n = [service insertupdatedeletewithquery:query indatabase:@"wavedb.sql"];                         nslog(@"%d",n);                          nsarray *arr = [data objectforkey:@"intrests"];                         (int = 0; < arr.count; i++) {                             nslog(@"%@",[arr objectatindex:i]);                              query = [nsstring stringwithformat:@"insert usercategory (user_id, cat_id) values ('%@','%@')",[[nsuserdefaults standarduserdefaults]objectforkey:@"userid"],[arr objectatindex:i]];                             [service insertupdatedeletewithquery:query indatabase:[dataclass databasename]];                         }                            dispatch_async(dispatch_get_main_queue(), ^{                             [(appdelegate *)[[uiapplication sharedapplication]delegate]hideprogress];                             [[nsuserdefaults standarduserdefaults]setbool:yes forkey:@"login"];                             wallviewcontroller *main = [self.storyboard instantiateviewcontrollerwithidentifier:@"wallview"];                             [self.navigationcontroller pushviewcontroller:main animated:yes];                         });                     }                     else {                         [(appdelegate *)[[uiapplication sharedapplication]delegate]hideprogress];                         uialertview *alert = [[uialertview alloc]initwithtitle:@"alert!" message:@"invalid username , password" delegate:self cancelbuttontitle:@"ok" otherbuttontitles: nil];                         [alert show];                     }                 } failure:^(afhttprequestoperation operation, nserror error) {                     nslog(@"error: %@", error);                     dispatch_async(dispatch_get_main_queue(), ^{                         [(appdelegate *)[[uiapplication sharedapplication]delegate]hideprogress];                         uialertview *alert = [[uialertview alloc]initwithtitle:@"alert!" message:@"some technical error occured. try later." delegate:self cancelbuttontitle:@"ok" otherbuttontitles: nil];                         [alert show];                      });                 }];                }); 

check reachability before code execution solved problem.


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -