首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iOS 6.0中不推荐使用TWRequest -我可以使用什么来代替?

iOS 6.0中不推荐使用TWRequest -我可以使用什么来代替?
EN

Stack Overflow用户
提问于 2012-11-11 19:12:54
回答 4查看 8.4K关注 0票数 25

我正在为iOS应用程序开发一个Twitter Feed View。我找到了TWRequest,它的工作方式和我要找的一模一样。但是:我收到一则通知:"TWRequest已被弃用:在iOS 6.0中首次被弃用“。我应该用什么来代替呢?

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2012-11-11 19:14:58

在iOS 6上,您应该使用Social.framework。它有一个名为SLRequest的类。

它的使用方式与已弃用的TWRequest几乎相同,但您需要指定它是twitter请求,而不是facebook请求。

从iOS 6开始,整个Twitter.framework就被弃用了,因为苹果在iOS 6中加入了脸书和微博(中国的社交网络),他们将所有的社会阶层都归入了新的Social.framework

注意:您必须指定Twitter/Facebook的服务类型,例如:

代码语言:javascript
复制
SLRequest *aRequest  = [SLRequest requestForServiceType:SLServiceTypeTwitter
                                          requestMethod:SLRequestMethodPOST
                                                    URL:myurl
                                             parameters:myparams];

请务必查看documentation

票数 59
EN

Stack Overflow用户

发布于 2015-01-12 20:35:01

这里是一个完整的代码,可以使用Twitter api将文本+图像上传到您的Twitter帐户

代码语言:javascript
复制
    UIImage *img = [UIImage imageNamed:@"twitterImage.png"];
    ACAccountStore *account = [[ACAccountStore alloc] init];
    ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
    [account requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
        if (granted == YES) {
            // Populate array with all available Twitter accounts
            NSArray *arrayOfAccounts = [account accountsWithAccountType:accountType];
            if ([arrayOfAccounts count] > 0) {
                ACAccount *acct = [arrayOfAccounts objectAtIndex:0];
                NSDictionary *message = @{@"status": @"From my app"};
                NSURL *requestURL = [NSURL URLWithString:@"https://upload.twitter.com/1/statuses/update_with_media.json"];
                SLRequest *postRequest = [SLRequest
                                                  requestForServiceType:SLServiceTypeTwitter
                                                  requestMethod:SLRequestMethodPOST
                                                  URL:requestURL parameters:message];
                NSData *data = UIImagePNGRepresentation(img);
                [postRequest addMultipartData:data withName:@"media" type:@"image/png" filename:@"TestImage"];
                postRequest.account = acct;

                [postRequest performRequestWithHandler:
                     ^(NSData *responseData, NSHTTPURLResponse
                       *urlResponse, NSError *error)
                     {
                         if (error) {
                             NSLog(@"%@",error.description);
                         }
                         else {
                             NSLog(@"Upload Sucess !");
                         }
                     }];
            }
        }
    }];
票数 2
EN

Stack Overflow用户

发布于 2015-02-19 17:36:28

如果您计划通过Twitter集成TwitterKit,以便通过您的自定义twitter应用程序执行tweet,那么这可能对您有所帮助。

https://stackoverflow.com/a/28602749/1740354

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13330596

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档