Detecting if Twitter account is set up on iOS 7 - ios

I've been following some tutorials on integrating Twitter into my application. Here is what I have so far:
- (IBAction)postToTweeter:(id)sender {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
SLComposeViewController *tweetSheet = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:#"this is a test"];
[self presentViewController:tweetSheet animated:YES completion:nil];
}
}
My storyboard has a button, and when a user taps that button, this is the code that gets called. However, this only works whenever they have a Twitter account setup on their iPhone first. How can I handle the case where a user has not set up a twitter account yet, and show them an alert instructing them to add a Twitter account?

SLComposeViewController has a very handy built-in mechanism, whereby it will offer to send the user to Settings if you instantiate a ComposeViewController when the user hasn't set up / logged into the social-media service in question. To test this, all you need to do is remove the conditional so your code looks like this:
- (IBAction)postToTweeter:(id)sender {
SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:#"this is a test"];
[self presentViewController:tweetSheet animated:YES completion:nil];
}
...and you'll find that iOS will automatically pop up an alert which will take the user through to Settings.
Note that I've found that this doesn't tend to work in the simulator, so it's best to test on a device.

Related

SLComposeViewController setInitialText not working on Twitter in iOS 11

I am creating a SLComposeViewController of type SLServiceTypeTwitter and I'm adding an url and text to it. However, the text is not shown, only the url.
Does anybody know why SLComposeViewController's setInitialText is not working on Twitter in iOS 11?
Here is a snippet of my code:
SLComposeViewController *twPostSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[twPostSheet setInitialText:copy];
[twPostSheet addURL:[NSURL URLWithString:url]];
UIViewController *controller = RCTPresentedViewController();
twPostSheet.completionHandler = ^(SLComposeViewControllerResult result) {
// Shared with success
};
[controller presentViewController:twPostSheet animated:YES completion:nil];
This behaviour is intended. You should use Twitter iOS kit. With it you can share Tweets with text, URLs, photos and video. The same goes for Facebook share.

Share image to Facebook (IOS app/Objective-C)

pls help. I have not made an update to my app in over a year. Now I tried to add a button to share an image to Facebook. But the button will not don't work. In general, nothing happens after pressing on it. How can I fix it ?
Best regards,
Ivan (yeah yeah my english is poor)
-(void)shareWithFacebook{
NSLog(#"fb");
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
SLComposeViewController *fbSheet = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeFacebook];
[fbSheet setInitialText:#"Document from Docement scanner"];
[fbSheet addImage:self.savedImage];
[self presentViewController:fbSheet animated:YES completion:nil];
}
}

How can I set fixed text for twitter posts?

I would like the twitter posts from my app to be fixed so that users cannot edit them before posting. How can I achieve this? Below is the basic code I am using to post normal editable text.
-(void)tweetResults {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:#"Tweeting from my own app! :)"];
[self presentViewController:tweetSheet animated:YES completion:nil];
CCLOG(#"it's working okay");
}
}
Your best bet would be either subclassing SLComposeViewController, or creating your own custom class using lower level API access to the users Twitter account.

share twitter detail throughout the app

I am implement twitter share in my IOS app. I ma using MGTwitterEngine. If I implement login and sharing from the same controller it is working but if I separate out login and share functionality in 2 controllers it is not working.
SA_OAuthTwitterEngine *_engine;
_engine returning blank.
If you're targeting iOS6 or newer, you'll be better use iOS social API:
- (IBAction)postToTwitter:(id)sender {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewController *tweetSheet = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:#"Great fun to learn iOS programming at appcoda.com!"];
[self presentViewController:tweetSheet animated:YES completion:nil];
}
}
For more info see here: http://www.appcoda.com/ios-programming-101-integrate-twitter-and-facebook-sharing-in-ios-6/

iPhone app freezes on presentViewController with SLComposerViewController

I am implementing sharing with Facebook and Twitter - On the simulator both of these work, but on my iPhone 4S running iOS6 the Facebook button freezes the app. The code is the same as it is for the Twitter and functions the same (it hits presentViewController, then the app just stops responding).
The code is as follows:
SLComposeViewController *mulitpartPost = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
// Set the text of the tweet
[mulitpartPost setInitialText:[NSString stringWithFormat:#"I've had a change in weight of "]];
// Add the image to the tweet
if([[NSUserDefaults standardUserDefaults] boolForKey:#"fbProgPicShare"])
[mulitpartPost addImage:[_imgCurrent image]];
mulitpartPost.completionHandler = ^(SLComposeViewControllerResult res){
[self dismissViewControllerAnimated:YES completion:nil];
};
// Display the tweet sheet to the user
[self presentViewController:mulitpartPost animated:YES completion:nil];
isAvailableForServiceType also returns YES if I put that into the code - so I cannot think of why this would freeze when the Twitter button works on the phone. Both Twitter and FB accounts are setup.
Any help would be appreciated.
Strange Fix
It seems to work consistantly now that I do
// Display the tweet sheet to the user
if(!(multipartPost == nil))
[self presentViewController:mulitpartPost animated:YES completion:nil];
Otherwise it still freezes.

Resources