Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to wait then perform an action based on HTTPrequest response iOS
    primarykey
    data
    text
    <p>I have class that post a tweet to twitter using HTTP Post</p> <p>here is a bit of code <code>PostTweet.h</code></p> <pre><code>@interface PostTweet : NSObject - (void)postMyTweet; @end </code></pre> <p><code>PostTweet.m</code></p> <pre><code>- (void)postMyTweet { accountStore = [[ACAccountStore alloc] init]; accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]; [accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error) { if (granted) { allAccounts = [accountStore accountsWithAccountType:accountType]; if ([allAccounts count] &gt; 0) { userAccount = [allAccounts objectAtIndex:0]; userName = userAccount.username; NSURL * reqURL = [NSURL URLWithString:ENDPOINT_MEDIA_UPLOAD]; NSDictionary * parameter = [NSDictionary dictionaryWithObject:tweetTitle forKey:@"status"]; SLRequest *twitterInfoRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodPOST URL:reqURL parameters:parameter]; [twitterInfoRequest addMultipartData:tweetImage withName:PARAM_MEDIA type:CONTENT_TYPE_MULTIPART_FORM_DATA filename:nil]; [twitterInfoRequest setAccount:userAccount]; [twitterInfoRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { //show status after done long result = [urlResponse statusCode]; //Let us say that every thing is ok and I got 200 response if (result == 200) { NSLog(@"%ld",result); } } ]; } } else { NSLog(@"Not authorized"); } }]; } </code></pre> <p>In my <code>viewcontroller.m</code></p> <pre><code>- (void) actuallySendTweet { PostTweet * pt = [[PostTweet alloc] init]; [pt postTweet]; NSLog(@"Done"); } </code></pre> <p>The Question is: after calling The testMethod, How to wait for the http request response and I can do anything based on the response.</p> <p>What happens now is that as soon as I call the testMethod the <code>NSLog</code> perform right away and does not wait for the http response.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload