Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vtourraine/vtfollowontwitter
Ready to use “Follow me on Twitter” native implementation.
https://github.com/vtourraine/vtfollowontwitter
Last synced: 3 months ago
JSON representation
Ready to use “Follow me on Twitter” native implementation.
- Host: GitHub
- URL: https://github.com/vtourraine/vtfollowontwitter
- Owner: vtourraine
- License: mit
- Created: 2013-05-26T17:13:46.000Z (over 11 years ago)
- Default Branch: main
- Last Pushed: 2021-02-01T13:57:47.000Z (almost 4 years ago)
- Last Synced: 2024-10-02T22:16:44.739Z (3 months ago)
- Language: Objective-C
- Homepage:
- Size: 49.8 KB
- Stars: 7
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# VTFollowOnTwitter
_Ready to use “Follow me on Twitter” native implementation._
![Platform iOS](https://img.shields.io/badge/platform-iOS-blue.svg)
[![CocoaPods compatible](https://img.shields.io/cocoapods/v/VTFollowOnTwitter.svg)](https://cocoapods.org/pods/VTFollowOnTwitter)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg)](https://github.com/Carthage/Carthage)
[![CocoaPods documentation](https://img.shields.io/cocoapods/metrics/doc-percent/VTFollowOnTwitter.svg)](http://cocoadocs.org/docsets/VTFollowOnTwitter)
[![MIT license](http://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/vtourraine/VTFollowOnTwitter/raw/master/LICENSE)## How To Get Started
Instead of adding the source files directly to your project, you may want to consider using [CocoaPods](http://cocoapods.org/) to manage your dependencies. Follow the instructions on the CocoaPods site to install the gem, and specify VTFollowOnTwitter as a dependency in your Podfile:
```
pod 'VTFollowOnTwitter', '~> 0.5'
```You can also download VTFollowOnTwitter source files, and add them to your project, with ARC enabled. Don’t forget to add the `Accounts` and `Social` frameworks in your target configuration.
## Example Usage
The main method needs the Twitter username to follow.
``` objc
[VTFollowOnTwitter followUsername:@"test"
fromPreferredUsername:nil
success:^{ /* Good */ }
multipleAccounts:^(NSArray *usernames) { /* Need specific username */ }
failure:^(NSError *error) { /* Not good */ }];
```Your controller need to handle the case where the user has more than one Twitter account configured. For instance, you can use a `UIActionSheet` to present the choice if necessary.
``` objc
@interface VTViewController : UIViewController- (IBAction)followOnTwitter:(id)sender;
@end
// ---
@interface VTViewController ()- (void)followOnTwitterFromUsername:(NSString *)fromUsername;
@end
@implementation VTViewController
- (IBAction)followOnTwitter:(id)sender {
[self followOnTwitterFromUsername:nil];
}- (void)followOnTwitterFromUsername:(NSString *)fromUsername {
NSString *username = @"StudioAMANgA";[VTFollowOnTwitter followUsername:username fromPreferredUsername:fromUsername success:^{
[[[UIAlertView alloc] initWithTitle:@"Thanks!" message:nil delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
} multipleAccounts:^(NSArray *usernames) {
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Which account do you want to follow us with?" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
for (NSString *username in usernames)
[actionSheet addButtonWithTitle:[@"@" stringByAppendingString:username]];
[actionSheet addButtonWithTitle:@"Cancel"];
[actionSheet setCancelButtonIndex:[usernames count]];
[actionSheet showInView:self.view];
} failure:^(NSError *error) {
[[[UIAlertView alloc] initWithTitle:@"Request Error" message:[NSString stringWithFormat:@"Sorry, something went wrong.\n%@", [error localizedDescription]] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
}];
}- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex != actionSheet.cancelButtonIndex) {
[self followOnTwitterFromUsername:[[actionSheet buttonTitleAtIndex:buttonIndex] stringByReplacingOccurrencesOfString:@"@" withString:@""]];
}
}@end
```## Requirements
VTFollowOnTwitter requires iOS 6.0 and above, with the `Accounts` and `Social` frameworks, Xcode 6.3 and above, and uses ARC.
## Credits
VTFollowOnTwitter was created by [Vincent Tourraine](http://www.vtourraine.net).
## License
VTFollowOnTwitter is available under the MIT license. See the LICENSE file for more info.