【发布时间】:2023-03-07 13:53:02
【问题描述】:
我正在使用 Twitter API 发布推文。有时这可能需要一些时间,所以我想在后台执行“推文发布”操作。为此,我正在使用 GCD,如下所示:
- (void)myClassMethodToPostTweet {
dispatch_async(network_queue, ^{
// … construct the tweet message
NSString *tweet = @"…";
// … check if network is available
[self isConnectedToWeb];
// … initialize twitter API
TwitterAPIClass *twitterAPI = [[[TwitterAPIClass alloc] init…] autorelease];
twitterAPI.delegate = self;
twitterAPI.APIKey = ...;
twitterAPI.APISecret = ...;
// … use twitter API to post the tweet
[twitterAPI postTweet:tweet];
});
}
...
/* and when the API reports a successful operation, update the required variables and UI */
...
- (void)twitterAPIDelegateMethodReportingOperationSuccess {
// … update any variables/records
// … update UI
dispatch_async(dispatch_get_main_queue(), ^{
// … UI updation code
});
}
问题是,我没有收到委托回调!我错过了什么?
【问题讨论】:
-
你使用的是哪个 Twitter API?
标签: iphone asynchronous event-handling objective-c-blocks grand-central-dispatch