简体   繁体   中英

Post screenshot in tweet on iOS

Trying to post a screenshot in a tweet from within my app.. so far i've gotten it to save it to the library but I need to tweet it... Here's a look at the screenshot and the empty twitter post...

- (IBAction)savephoto:(id)sender {

// Returns 1024x768 for iPad Retina
CGSize screenDimensions = [[UIScreen mainScreen] applicationFrame].size;

// Create a graphics context with the target size
// (last parameter takes scale into account)
UIGraphicsBeginImageContextWithOptions(screenDimensions, NO, 0);

// Render the view to a new context
CGContextRef context = UIGraphicsGetCurrentContext();
[customview.layer renderInContext:context];

// Save to Camera Roll
CGRect contentRectToCrop = CGRectMake(18, 14, 602, 460);
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();

CGImageRef imageRef = CGImageCreateWithImageInRect([screenshot CGImage], contentRectToCrop);
UIImage *croppedImage = [UIImage imageWithCGImage:imageRef];
UIImageWriteToSavedPhotosAlbum(croppedImage, self, nil, nil);

UIGraphicsEndImageContext();

.........

- (IBAction)tweetphoto:(id)sender {

TWTweetComposeViewController *twitter = [[TWTweetComposeViewController alloc] init];
[twitter setInitialText:@"Enter tweet here!"];
[twitter addImage:[UIImage imageNamed:@""]];

........

Can't figure out what to type in the imageNamed...

[...]
UIImage* croppedImage = [UIImage imageWithCGImage:imageRef];

TWTweetComposeViewController *twitter = [[TWTweetComposeViewController alloc] init];
[twitter setInitialText:@"Enter tweet here!"];
[twitter addImage:croppedImage];

UIGraphicsEndImageContext();

Why dont you use the "cropped image" object which you have already created..You dont need to create another using

[UIimage imageName:@""];

Helpfull ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM