AFNetworking を使用して、次のブロックを使用して削除 Web サービスにデータを送信します。
self.operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
[self updateAfterPost];
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id jsonObject) {
[handle error]
}];
- (void)updateAfterPost
{
if ([AppController sharedAppController].currentUser.twitterAccount.crossPost.boolValue == YES) {
[self postToTwitter];
}
[other things that should update the UI]
}
- (void)postToTwitter
{
ACAccountType *accountType = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[self.accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error) {
if (granted == YES) {
if ([self.twitterAccounts count] > 0) {
ACAccount *twitterAccount = [self.twitterAccounts objectAtIndex:[AppController sharedAppController].currentUser.twitterAccount.accountId.integerValue];
NSDictionary *message = @{@"status":self.postTextField.text};
NSURL *requestURL = [NSURL URLWithString:@"http://api.twitter.com/1/statuses/update.json"];
SLRequest *postRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodPOST URL:requestURL parameters:message];
postRequest.account = twitterAccount;
[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
}];
}
}
}];
}
アクションのpostToTwitter
結果、次の警告が表示されます (メソッドのコメントを外しても警告は表示されません)。
Obtaining the web lock from a thread other than the main thread or the web thread. UIKit should not be called from a secondary thread.
解決方法がわかりません。私はNSNotification
成功ブロックで試しましたが、うまくいきませんでした (通知はおそらくバックグラウンド スレッドでも送信されます)。アイデアや提案はありますか?
アップデート
も試し[self performSelectorOnMainThread:@selector(updateAfterPost) withObject:nil waitUntilDone:YES];
ました。