ios - 是否有适用于 Twitter 的 Firebase iOS 简单登录示例?

标签 ios objective-c firebase firebasesimplelogin

我无法从 Simple Login iOS 中找到解决以下问题的方法 quick start :

Since it is possible for a device to have more than one Twitter account attached, you will need to provide a block which can be used to determine which account to log in. Replace "[yourApp selectUserName:usernames]" below with your own code to choose from the list of usernames.

这是提供的代码:

[authClient loginToTwitterAppWithId:@"YOUR_CONSUMER_KEY"
multipleAccountsHandler:^int(NSArray *usernames) {

// If you do not wish to authenticate with any of these usernames, return NSNotFound.
return [yourApp selectUserName:usernames];
} withCompletionBlock:^(NSError *error, FAUser *user) {
    if (error != nil) {
        // There was an error authenticating
    } else {
        // We have an authenticated Twitter user
    }
}];

允许用户选择要使用的帐户的 UIActionSheet 是否最好?那将如何完成?

最佳答案

#import <Twitter/Twitter.h>
#import <Accounts/Accounts.h>

登录方式:

  ACAccountStore *accountStore = [[ACAccountStore alloc] init];

// Create an account type that ensures Twitter accounts are retrieved.
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error) {


    // Request access from the user to use their Twitter accounts.
    //    [accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {

    //NSLog(@"%@",error);
    if(granted) {

        // Get the list of Twitter accounts.
        NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];
        //NSLog(@"%@",accountsArray);
        twitterAccountsArray=[accountsArray mutableCopy];



        if ([twitterAccountsArray count] > 0){
            sheet = [[UIActionSheet alloc] initWithTitle:@"Choose an Account" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
            for (ACAccount *acct in twitterAccountsArray) {
                [sheet addButtonWithTitle:acct.username];
            }




        }

    }

    else{
        dispatch_async(dispatch_get_main_queue(), ^{
            //NSLog(@"%@",error);

            if (![error.localizedDescription isEqual:[NSNull null]] &&[error.localizedDescription isEqualToString:@"No access plugin was found that supports the account type com.apple.twitter"]) {



            }
            else


            [Utility showAlertWithString:@"We could not find any Twitter account on the device"];

        });
    }

}];

它将打开一个操作表,其中会显示您的设备拥有的帐户列表。

用于发布:

您的 iPhone 设备上必须至少添加一个有效的 Twitter 帐户。

if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{

  NSString *initialText=@"Text to be posted";


    SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];

    tweetSheet.completionHandler = ^(SLComposeViewControllerResult result) {


        switch(result) {
                //  This means the user cancelled without sending the Tweet
        case SLComposeViewControllerResultCancelled:{

        }
        break;

        case SLComposeViewControllerResultDone:{



    }
                break;
    }

    };
    [tweetSheet setInitialText:initialText];
    if (initialText) {


        [self presentViewController:tweetSheet animated:YES completion:nil];

    }

}

关于ios - 是否有适用于 Twitter 的 Firebase iOS 简单登录示例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24886725/

相关文章:

ios - 在 Swift 中从 Wifi 切换到 Cellular 时出现可达性错误

iphone - CGContextSaveGState 无效上下文

node.js - 从 Firebase 中删除的用户的 UID 是否会重新用于新用户?

ios - Sharepoint 2010,HTML5 视频无法在 iPad 上运行

iphone - 如何返回从 objective-c (iPhone) 中的 Web 服务获取的数据?

iphone - 从 objective-c 中的代码设置内部时钟

ios - 我的应用程序因为缺少 "significant account-specific functionality from Google"而被拒绝

ios - OpenGLES : render buffer parameters in landscape orientation

ios - 写入扩展文件属性

ios - 使用 Cocoapods 添加 Firebase 时的 Apple Mach-O 链接器错误组