IOS7 - SLComposeViewController - Include links / Images? - ios

I'm building an IOS7 Native app on behalf of a client - its for Fitness Instructors.
The brief requests that the clients can socially share progress updates - which include a link to the instructors site to help promotion, for example - 'Joe ran 3000 miles with the help of Debbie Personal Trainer' and ideally a little pic of the trainer.
I've looked at the SLComposeViewController and can easily create the tweet string but I don't know how to add a URL and image to this - does anyone know if its possible?

Import framework <Twitter/Twitter.h> and <Social/Social.h>.
-(void)sendFacebook:(id)sender {
SLComposeViewController *composeController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[composeController setInitialText:#"look me"];
[composeController addImage:[UIImage imageNamed:#"image.png"]];
[composeController addURL: [NSURL URLWithString:#"http://www.apple.com"]];
[self presentViewController:composeController animated:YES completion:nil];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultCancelled) {
NSLog(#"delete");
} else {
NSLog(#"post");
}
// [composeController dismissViewControllerAnimated:YES completion:Nil];
};
composeController.completionHandler =myBlock;
}
- (void)sendTwitter:(id)sender {
SLComposeViewController *composeController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[composeController setInitialText:#"look me"];
[composeController addImage:[UIImage imageNamed:#"image.png"]];
[composeController addURL: [NSURL URLWithString:
#"http://www.apple.com"]];
[self presentViewController:composeController
animated:YES completion:nil];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultCancelled) {
NSLog(#"delete");
} else {
NSLog(#"post");
}
// [composeController dismissViewControllerAnimated:YES completion:Nil];
};
composeController.completionHandler =myBlock;
}

This is almost the same answer as llario, but follows Apple docs instructions and employs defensive coding with some additional error checking.
#import <Social/Social.h>
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
SLComposeViewController *composeViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
if (composeViewController) {
[composeViewController addImage:[UIImage imageNamed:#"MyImage"]];
[composeViewController addURL:[NSURL URLWithString:#"http://www.google.com"]];
NSString *initialTextString = #"Check out this Tweet!";
[composeViewController setInitialText:initialTextString];
[composeViewController setCompletionHandler:^(SLComposeViewControllerResult result) {
if (result == SLComposeViewControllerResultDone) {
NSLog(#"Posted");
} else if (result == SLComposeViewControllerResultCancelled) {
NSLog(#"Post Cancelled");
} else {
NSLog(#"Post Failed");
}
}];
[self presentViewController:composeViewController animated:YES completion:nil];
}
}

Related

SLServiceTypeTwitter in iOS11 ond over

I have the code:
#import <Social/Social.h>
//...
//...
-(void)work {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[controller setInitialText:#"Its example text for Twitter"];
[controller addImage:[UIImage imageNamed:#"automobile"]];
[controller addURL:[NSURL URLWithString:#"http://www.auto.ru"]];
controller.completionHandler = ^(SLComposeViewControllerResult result) {
NSLog(#"*** %#", NSStringFromSelector(_cmd));
};
} else {
NSLog(#"The twitter service is not available");
}
}
but i have warning:
'SLServiceTypeTwitter' is deprecated: first deprecated in iOS 11.0
and log:
...[core] isAvailableForServiceType: for com.apple.social.twitter returning NO
...The twitter service is not available
Hope me please?

How to share photos to Twitter app from my app?

I build an app, when I share photos to Twitter app from my app (by IOS shared-button), it can only display links, I would like to be a display Picture. How can I achieve it?
Try this first you need to import Social framework
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
SLComposeViewController *composeViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
if (composeViewController) {
[composeViewController addImage:[UIImage imageNamed:#"Your Image"]];
[composeViewController addURL:[NSURL URLWithString:#"Your URL"]];
NSString *initialTextString = #"Tour Tweet";
[composeViewController setInitialText:initialTextString];
[composeViewController setCompletionHandler:^(SLComposeViewControllerResult result) {
if (result == SLComposeViewControllerResultDone) {
NSLog(#"Posted");
} else if (result == SLComposeViewControllerResultCancelled) {
NSLog(#"Post Cancelled");
} else {
NSLog(#"Post Failed");
}
}];
[self presentViewController:composeViewController animated:YES completion:nil];
}
}
Please go through https://developer.apple.com/library/ios/documentation/NetworkingInternet/Reference/SLComposeViewController_Class/ for more information about SLComposeViewController
Try this you can easily share photo on twitter from your app. and you can also access other options of twitter.
https://github.com/ronaldwang/FHSTwitterEngine

Push to Twitter from my app used to work - now it doesn't

I push a message to Twitter and/or Facebook at the request of the user.
This has been working for months and now it has stopped, for Twitter only.
This is my code:
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewController *tweetSheet = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:twoatText];
BOOL weHaveAPhoto = [[passTwoat objectForKey:#"photoSaved"] boolValue];
if (weHaveAPhoto)
{
PFFile *photoFile = [passTwoat objectForKey:#"photo"];
[photoFile getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error)
{
if (!error)
{
UIImage *fullImage = [UIImage imageWithData:imageData];
[tweetSheet addImage:fullImage];
fullImage = nil;
}
else
{
[tweetSheet addImage:lclImage];
}
[self presentViewController:tweetSheet animated:YES completion:nil];
}];
}
else
{
if (lclImage)
{
[tweetSheet addImage:lclImage];
}
[self presentViewController:tweetSheet animated:YES completion:nil];
tweetSheet = nil;
lclImage = nil;
twoatText = nil;
passTwoat = nil;
}
}
The 'If' statement fails and so does not execute the push to Twitter. I guess something has changed, and any ideas would be most welcome.
I solved it. In my iPhone Settings, Twitter was not allowing my App to send messages to Twitter, so I just changed this and all was fine.

iOS - Facebook Post

I'm looking to add functionality that when an event happens on my app, it will post to my facebook timeline. That said, I'm trying to get it to look very similar to how when you post a youtube video to the timeline where there is a thumbnail image to the left and a title and subtitle next to it.
Anyone have any ideas how I can accomplish this?
You can't make a post automatically from code, but you can open a system window with predefined message and image attachment.
Sample code:
- (BOOL)postToFacebook:(NSString*)title andDescription:(NSString*)description {
UIWindow *frontWindow = [[UIApplication sharedApplication] keyWindow];
UIViewController *vc = [frontWindow rootViewController];
BOOL success = NO;
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result) {
if (result == SLComposeViewControllerResultCancelled) {
} else {
}
[controller dismissViewControllerAnimated:YES completion:Nil];
};
controller.completionHandler = myBlock;
[controller setTitle:title];
[controller setInitialText:description];
[controller addURL:[NSURL URLWithString:#"http://example.com"]];
[controller addImage:[UIImage imageNamed:#"sampleImage.png"]];
[vc presentViewController:controller animated:YES completion:^{
}];
success = YES;
}
return success;
}
Remember to add two frameworks:
Social.framework
Accounts.framework

how can i get Followers list from Twitter in iphone programmatically?

here i have a piece of code
(void)postToTwitter:(id)sender
{
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:#"Great fun to learn iOS programming at softwareWeaver!"];
[self presentViewController:tweetSheet animated:YES completion:nil];
}
}
but what next to do ????
You can use the STTwitter library which makes all of this very very easy:
self.twitter = [STTwitterAPI twitterAPIOSWithFirstAccount];
[_twitter verifyCredentialsWithSuccessBlock:^(NSString *username) {
[_twitter getFollowersForScreenName:username successBlock:^(NSArray *followers) {
NSLog(#"-- %#", followers);
} errorBlock:^(NSError *error) {
//
}];
} errorBlock:^(NSError *error) {
//
}];

Resources