objective c - Stop Recursion in Blocks -
so dealing networking cookie authentication. if 401 or 406 unauthorized, know cookie has expired (valid 1 hr), login stored token new cookie. once that, want try call again, recursive call on block. in unknown case if continue 401 or 406 after successful cookie refresh, infinitely recurse. want try 1 more time. how stop it?
i tried setting requestid
-1 after first call , set in if statement if(requestid == -1)
don't recurse. since requestid block variable, throws exception "variable not assignable (missing __block type specifier`
+ (void)fullrequestwithblock:(void (^)(nsdictionary *fullrequest, nserror *error))block forid: (nsstring*) requestid foruid: (nsstring *) userid{ nsstring *pathsuffix = [nsstring stringwithformat:@"getrequestinfo?requestid=%@&userid=%@", requestid, userid]; [[afappapiclient sharedclient] getpath:pathsuffix parameters:[nsdictionary dictionarywithobject:@"false" forkey:@"include_entities"] success:^(afhttprequestoperation *operation, id json) { id innerjson = [json objectforkey:@"d"]; //nsstringencoding encoding; nsmutabledictionary *requestdata = [[nsmutabledictionary alloc] initwithdictionary:innerjson]; [requestdata removeobjectforkey:@"requestor"]; [requestdata removeobjectforkey:@"shortdesc"]; [requestdata removeobjectforkey:@"fulldesc"]; if (block) { block([nsdictionary dictionarywithdictionary:fulldescription], nil); } } failure:^(afhttprequestoperation *operation, nserror *error) { if ([[[error localizeddescription] substringfromindex:[[error localizeddescription] length] - 3] isequaltostring:@"406"]) { nsuserdefaults *userdefaults = [nsuserdefaults standarduserdefaults]; nsstring *storedtoken = [userdefaults stringforkey:@"storedtoken"]; [login tokenloginidwithblock:^(nsstring *userid, nserror *error) { if (!error) { nslog(@"reaunthenciated user id: %@", userid); [self fullrequestwithblock:^(nsdictionary *requests, nserror *error) { if (!error) { if (block) { block([nsdictionary dictionarywithdictionary:requests], nil); } } else{ block([nsdictionary dictionary], error); } } forid:requestid foruid:userid]; } else{ block([nsdictionary dictionary], error); } } fortoken:storedtoken]; } } else if (block) { block([nsdictionary dictionary], error); } }];
}
Comments
Post a Comment