VTFollowOnTwitter 0.5

VTFollowOnTwitter 0.5

测试已测试
语言语言 Obj-CObjective C
许可协议 MIT
发布最新发布2015年12月

Vincent Tourraine维护。



准备好了使用“关注 Twitter”的本地实现。

如何开始

您可以考虑使用 CocoaPods 来管理您的依赖项,而不是直接将源文件添加到项目中。按照 CocoaPods 站点的说明安装 gem,并在 Podfile 中指定 VTFollowOnTwitter 作为依赖项

pod 'VTFollowOnTwitter', '~> 0.5'

您还可以下载 VTFollowOnTwitter 的源文件,并启用 ARC 将其添加到您的项目中。请不要忘记在目标配置中添加 AccountsSocial 框架。

示例用法

主方法需要要关注到的 Twitter 用户名。

[VTFollowOnTwitter followUsername:@"test"
            fromPreferredUsername:nil
                          success:^{ /* Good */ }
                 multipleAccounts:^(NSArray *usernames) { /* Need specific username */ } 
                          failure:^(NSError *error) { /* Not good */ }];

您的控制器需要处理用户已经配置了多个 Twitter 帐户的情况。例如,您可以使用 UIActionSheet 来提供必要的选项。

@interface VTViewController : UIViewController

- (IBAction)followOnTwitter:(id)sender;

@end

// ---
@interface VTViewController () <UIActionSheetDelegate>

- (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

要求

VTFollowOnTwitter 需要 iOS 6.0 及以上版本,包含 AccountsSocial 框架,Xcode 6.3 及以上版本,并使用 ARC。

致谢

VTFollowOnTwitter 由 Vincent Tourraine 创建。

许可协议

VTFollowOnTwitter 在 MIT 许可协议下可用。有关更多信息,请参阅 LICENSE 文件。