Ios5 iOS'支持自动共享吗;什么是twitter框架?

Ios5 iOS'支持自动共享吗;什么是twitter框架?,ios5,twitter,Ios5,Twitter,我有一个名为twitter的按钮,当我点击这个按钮时,通常会显示一个tweet视图,即tweetcomposeviewcontroller。我有两种推文方式,即自动共享和正常共享。正常共享工作正常,但我怀疑如何在自动共享中做到这一点,即当我单击推文按钮时自动推文一些默认消息,而不是显示tweetComposeViewController查看并单击完成按钮。最后我在ios5中搜索了这么多与Twitter相关的问题,也阅读了Twitter开发者文档并尝试了这个答案。我认为这是实现自动共享的解决方案之

我有一个名为twitter的按钮,当我点击这个按钮时,通常会显示一个tweet视图,即tweetcomposeviewcontroller。我有两种推文方式,即自动共享和正常共享。正常共享工作正常,但我怀疑如何在自动共享中做到这一点,即当我单击推文按钮时自动推文一些默认消息,而不是显示
tweetComposeViewController
查看并单击完成按钮。

最后我在ios5中搜索了这么多与Twitter相关的问题,也阅读了Twitter开发者文档并尝试了这个答案。我认为这是实现自动共享的解决方案之一

ACAccountStore *account = [[ACAccountStore alloc] init];
        ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

        // Request access from the user to access their Twitter account
        [account requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
            // Did user allow us access?
            if (granted == YES)
            {
                // Populate array with all available Twitter accounts
                NSArray *arrayOfAccounts = [account accountsWithAccountType:accountType];

                // Sanity check
                if ([arrayOfAccounts count] > 0) 
                {
                    // Keep it simple, use the first account available
                    ACAccount *acct = [arrayOfAccounts objectAtIndex:0];

                    NSURL *url = 
                    [NSURL URLWithString:
                     @"https://upload.twitter.com/1/statuses/update_with_media.json"];

                    //  Create a POST request for the target endpoint
                    TWRequest *request = 
                    [[TWRequest alloc] initWithURL:url 
                                        parameters:nil 
                                     requestMethod:TWRequestMethodPOST];

                    //  self.accounts is an array of all available accounts; 
                    //  we use the first one for simplicity
                    [request setAccount:acct];

                    //  The "larry.png" is an image that we have locally
                    UIImage *image = (UIImage *)[dictionarydata valueForKey:@"image"];
                    NSLog(@"%@",image);
                    if (image!=nil) {

                        //  Obtain NSData from the UIImage 
                        NSData *imageData = UIImagePNGRepresentation(image);


                        //  Add the data of the image with the 
                        //  correct parameter name, "media[]"
                        [request addMultiPartData:imageData 
                                         withName:@"media[]" 
                                             type:@"multipart/form-data"];

                        // NB: Our status must be passed as part of the multipart form data
                        NSString *status = [NSString stringWithFormat:@"%@ %@ %@",[dictionaryData valueForKey:@"firstname"],[dictionaryData valueForKey:@"lastname"],[dictionarydata valueForKey:@"title"]];

                        //  Add the data of the status as parameter "status"
                        [request addMultiPartData:[status dataUsingEncoding:NSUTF8StringEncoding] 
                                         withName:@"status" 
                                             type:@"multipart/form-data"];
                        //  Perform the request.  
                        //    Note that -[performRequestWithHandler] may be called on any thread,
                        //    so you should explicitly dispatch any UI operations to the main thread 
                        [request performRequestWithHandler:
                         ^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
                             NSDictionary *dict = 
                             (NSDictionary *)[NSJSONSerialization 
                                              JSONObjectWithData:responseData options:0 error:nil];

                             // Log the result
                             NSLog(@"%@", dict);

                             dispatch_async(dispatch_get_main_queue(), ^{
                                 // perform an action that updates the UI...
                             });
                         }];
                    }else{
                        NSURL *url = [NSURL URLWithString:@"https://api.twitter.com/1/statuses/update.json"];
                        NSDictionary *p = [NSDictionary dictionaryWithObjectsAndKeys:
                                           [NSString stringWithFormat:@"%@ %@ %@",[dictionaryData valueForKey:@"firstname"],[dictionaryData valueForKey:@"lastname"],[dictionarydata valueForKey:@"title"]], @"status",
                                           nil
                                           ];
                        TWRequest *postRequest = [[TWRequest alloc]
                                                  initWithURL:   url
                                                  parameters:    p
                                                  requestMethod: TWRequestMethodPOST
                                                  ];

                        // Post the request
                        [postRequest setAccount:acct];

                        // Block handler to manage the response
                        [postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
                            NSLog(@"Twitter response, HTTP response: %i", [urlResponse statusCode]);
                        }];
}
                }
            }
        }];

如果您一直在使用Twitter框架,您可以这样做:

NSString *statusesShowEndpoint = @"https://api.twitter.com/1.1/statuses/update.json";
NSDictionary *params = @{@"status": @"Great101 - https://share.livefrom.me/p/md5mrCp"};

NSError *clientError;
NSURLRequest *request = [[[Twitter sharedInstance] APIClient]
                         URLRequestWithMethod:@"POST"
                         URL:statusesShowEndpoint
                         parameters:params
                         error:&clientError];

if (request) {
    [[[Twitter sharedInstance] APIClient]
     sendTwitterRequest:request
     completion:^(NSURLResponse *response,
                  NSData  *data,
                  NSError *connectionError) {
         if (data) {
             // handle the response data e.g.
             NSError *jsonError;
             NSDictionary *dicResponse = [NSJSONSerialization
                                           JSONObjectWithData:data
                                           options:0
                                           error:&jsonError];
             NSLog(@"%@",[dicResponse description]);
         }
         else {
             NSLog(@"Error code: %ld | Error description: %@", (long)[connectionError code], [connectionError localizedDescription]);
         }
     }];
}
else {
    NSLog(@"Error: %@", clientError);
}

是的,可以使用tweet sheet[tweetSheet setInitialText:@“键入应该自动共享的内容”];tweetSheet是TWTweetComposeViewController na的对象?@iShru tweetSheet是TWTweetComposeViewController na的对象?这正在发生,但没有显示该工作表,我需要发送消息@iShru