Last active
August 29, 2015 14:18
-
-
Save balazsnemeth/0485c91472d6c78d0006 to your computer and use it in GitHub Desktop.
Post to Twitter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)sendTweetWithExperienceInfo:(NSDictionary*)info withCompletion:(void(^)(NSError *error))completion | |
{ | |
//Create basic post info. | |
NSString *status = [self tweetWithDescrition:[expInfo objectForKey:@"statusMessage"] withHeyLetsShortURL:expInfo[@"url"]]; | |
__block NSMutableDictionary *message = [@{ | |
@"status": status, | |
} mutableCopy]; | |
//if location info is presented, lets add them to the post. | |
if (expInfo[@"lat"]) { | |
message[@"lat"] = expInfo[@"lat"]; | |
} | |
if (expInfo[@"lon"]) { | |
message[@"long"] = expInfo[@"lon"]; | |
} | |
id image = [expInfo objectForKey:@"image"]; | |
if (image) { | |
//Image is presented, let's upload it | |
__weak typeof(self) weakSelf = self; | |
[self sendTweetWithImage:image withCompletion:^(NSNumber *mediaID, NSError *error) { | |
if (error) { | |
completion (error); | |
return; | |
} | |
if (mediaID) { | |
//Connect media ID to the tweet! | |
[message setObject:mediaID.stringValue forKey:@"media_ids"]; | |
[message setObject:@"1" forKey:@"trim_user"]; | |
} | |
//Post the media | |
[weakSelf postTwitterStatus:message withCompletion:completion]; | |
}]; | |
} | |
else { | |
[self postTwitterStatus:message withCompletion:completion]; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment