IOS7 - SLComposeViewController - Error posting to Twitter - cannot send tweet - connection failed - ios

I'm trying to implement a twitter post using IOS7 SLComposeViewController and I get the following error -
The Tweet "blah blah" cannot be sent because the connection to twitter failed.
I am including image and URL in my tweet - if that makes any difference..
code below -
SLComposeViewController *composeController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[composeController setInitialText:#"i ran with 18 chickens under my armpits for 18 hours"];
[composeController addImage:[UIImage imageNamed:#"zoeLrg.png"]];
[composeController addURL: [NSURL URLWithString:
#"http://www.nme.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;

Can you check your debug console to see what error is returned? Typically, those messages will be more informative. Also, if you have multiple accounts configured on your device, there is an open radar issue related to it which may apply in your case. Please check http://www.openradar.me/radar?id=5262535380959232.

Related

Twitter and Facebook Sharing in iOS application using Social Framework in iOS 8.4 adding URL not working in Objective C

Adding URL in Twitter and Facebook sharing in iOS application using Social framework for iOS 8.4 is not working.
Only setInitialText: method is working but not the addURL and setTile methods.
My code is as follows:
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *fbFeed = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[fbFeed setInitialText:self.travelogueTitle];
[fbFeed addURL:[NSURL URLWithString:self.saveTraveloguePublishedURL]];
[fbFeed setTitle:#"My Trip's Memories"];
NSLog(#"Save published url:%#",self.saveTraveloguePublishedURL);
NSLog(#"Share published url:%#",travelogue.publishedUrl);
// [fbFeed setInitialText:[NSString stringWithFormat:#"http://mvm064/MVPWeb/ViewTravelogue?travelogueId=OB1YlsTz/gngmCUTESuqlQ=="]];
[fbFeed setCompletionHandler:^(SLComposeViewControllerResult result) {
if (result == SLComposeViewControllerResultCancelled) {
NSLog(#"The user cancelled.");
}
else if (result == SLComposeViewControllerResultDone) {
NSLog(#"The user posted to Facebook");
}
}];
[self presentViewController:fbFeed animated:YES completion:nil];
}}
There is no method in SLComposeViewController to setTitle. SLComposeViewController is basically subclass of UIViewController so giving you facility to set title of SLComposeViewController. It will not going to post on Facebook. For post on Facebook you have method called setInitialText.
I have tried with your code and its get uploaded successfully, you can check out in following image.

Tweet is not sending from my real device

I have an app which build on Xcode using Objective-C. Users can send tweet, when I try to send from my iPhone it says (Can not Send Tweet, because the connection to Twitter failed). It is working with the simulator, her is the code I use:
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
NSString *tweetBody = self.currentList.tweetBody;
NSString *rawStr = [NSString stringWithFormat:#"%#", tweetBody];
SLComposeViewController *composeController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[composeController setInitialText:rawStr];
[composeController addURL: [NSURL URLWithString:#"https://my app url on Apple store"]];
[self presentViewController:composeController
animated:YES completion:nil];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultCancelled) {
NSLog(#"delete");
} else
{
NSLog(#"post");
}
};
composeController.completionHandler =myBlock;
}
}];
I hope to find the answer with you guys.
Have you checked the Privacy settings for Twitter? It's possible that you didn't grant it permission to access your Twitter accounts. The image below shows all apps that have been granted permission to access my Twitter account,

ios Social Framework Duplicate Tweet issue

I'm using Social Framework in iOS for Twitter integration
SLComposeViewController * composeVC = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
success = [composeVC setInitialText:[NSString stringWithFormat:#"xxx"]];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result)
{
if (result == SLComposeViewControllerResultCancelled)
{
}
else
{
[self shareApiCall:service];
}
[composeVC dismissViewControllerAnimated:YES completion:Nil];
};
As we are tweeting the same thing, it gives success in code, but then duplicate popup show. Is there any way we can know that the posted tweet was a duplicate tweet (through code)?

How do I post image and text to Twitter via Twitter native app?

How do I post image and text to Twitter via Twitter native app ?
Is there any Twitter api to tweet via native Twitter app in IOS programmatically ?
or , How can I post image using Social or Twitter framework via Twitter native app?
Thanks
Please Try this answer. I think this will help u
- (void)postToTwitter
{
SLComposeViewController *tweetSheet=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
// if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
// {
SLComposeViewControllerCompletionHandler __block completionHandler=^(SLComposeViewControllerResult result){
[tweetSheet dismissViewControllerAnimated:YES completion:nil];
switch(result){
case SLComposeViewControllerResultCancelled:
default:
{
NSLog(#"Cancel");
}
break;
case SLComposeViewControllerResultDone:
{
NSLog(#"Post");
}
break;
}
};
[tweetSheet setInitialText:#"your text"];
[tweetSheet addImage:[UIImage imageNamed:#"imageToSend"]];
[tweetSheet setCompletionHandler:completionHandler];
[self presentViewController:tweetSheet animated:YES completion:nil];
//}
}
Hi for sharing information via iOS app it is possible to use native share screen.
Using this code you going to share image via different social media.
UIImage *picture = [UIImage imageNamed:#"picture"];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:#[picture] applicationActivities:nil];

Facebook posting

here is what I did
Created an app on facebook
installed the FB SDK with all the requirements
logged in the user via a login button
now I am trying to post with the code provided here from this threat
How to Post to Facebook on iOS 6 in Objective-C using ACAccountStore class
But nothing happens. Am I missing a step?
This is the code I am using
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) //check if Facebook Account is linked
{
mySLComposerSheet = [[SLComposeViewController alloc] init]; //initiate the Social Controller
mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook]; //Tell him with what social plattform to use it, e.g. facebook or twitter
[mySLComposerSheet setInitialText:[NSString stringWithFormat:#"Test",mySLComposerSheet.serviceType]]; //the message you want to post
[mySLComposerSheet addImage:yourimage]; //an image you could post
//for more instance methodes, go here:https://developer.apple.com/library/ios/#documentation/NetworkingInternet/Reference/SLComposeViewController_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40012205
[self presentViewController:mySLComposerSheet animated:YES completion:nil];
}
[mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
NSString *output;
switch (result) {
case SLComposeViewControllerResultCancelled:
output = #"Action Cancelled";
break;
case SLComposeViewControllerResultDone:
output = #"Post Successfull";
break;
default:
break;
} //check if everything worked properly. Give out a message on the state.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Facebook" message:output delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alert show];
}];
Your setInitialText method is incorrect.
If you use stringWithFormat to post the serviceType, you need to add it to the method with "%#", otherwise there isn't anything there to say it to appear.
In short, just change :
[mySLComposerSheet setInitialText:[NSString stringWithFormat:#"Test",mySLComposerSheet.serviceType]];
to :
[mySLComposerSheet setInitialText:[NSString stringWithFormat:#"Test %#",mySLComposerSheet.serviceType]];

Resources