gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:17:50 42 4
gpt4 key购买 nike

我无法从 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/

42 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com