When i share an iTunes url on Facebook using SLComposerViewController, the post on Facebook is not showing the link description. Where as if i try some other URL's then i the post is showing the link description.
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[mySLComposerSheet addImage:[UIImage imageNamed:#"s_720.jpg"]];
[mySLComposerSheet setInitialText:#"check my swap card..."];
[mySLComposerSheet addURL:[NSURL URLWithString:[swap_card_dict valueForKey:#"swapcard_url"]]];
[mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
switch (result) {
case SLComposeViewControllerResultCancelled:
NSLog(#"Post Canceled");
break;
case SLComposeViewControllerResultDone:
{
NSLog(#"Post Sucessful");
}
break;
default:
break;
}
}];
[[self viewController] presentViewController:mySLComposerSheet animated:YES completion:nil];
}
Related
I am using Social framework for sharing from my iOS application and testing my iOS application on iOS9. When I click on share button it opens native facebook application ViewController as shown in following image.
The problem is that irrespective of user clicks post or hit back button it still return SLComposeViewControllerResultDone result. Here is my completion handler for SLComposeViewController. Here is code:
NSLog(#"%#Controller presenting",socialMediaSLType);//socialMediaSLType is SLServiceTypeFacebook
SLComposeViewController *controllerSLC = [SLComposeViewController composeViewControllerForServiceType:socialMediaSLType];
[controllerSLC setInitialText:#""];
[controllerSLC addURL:[NSURL URLWithString:link]];
[controllerSLC addImage:[UIImage imageNamed:[NSString stringWithFormat:#"%#%#",BASEURL,image]]];
[controllerSLC setCompletionHandler:^(SLComposeViewControllerResult result){
switch (result) {
case SLComposeViewControllerResultCancelled:
NSLog(#"Post Canceled");
break;
case SLComposeViewControllerResultDone:
NSLog(#"Post Done");
break;
}
}];
[self presentViewController:controllerSLC animated:YES completion:nil];
This question already has answers here:
iOS: How to share text and image on social networks?
(3 answers)
Closed 7 years ago.
I want to share photo and some text from the app on Facebook. I used SLComposeViewController class for sharing.
My problem is that when I tap on Facebook button a dialog box appears with image which I want to post but default text is not appearing in the device while in simulator it works perfectly fine. This code works perfectly for Twitter both in simulator and device. For more clarity I added code and an image
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result)
{
if (result == SLComposeViewControllerResultCancelled)
{
NSLog(#"Cancelled");
} else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Congratulations!" message:#"Photo is posted to facebook Wall." delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[alert show];
}
[controller dismissViewControllerAnimated:YES completion:Nil];
};
controller.completionHandler =myBlock;
str=[NSString stringWithFormat:#"Text to share"];
[controller setInitialText:str];
[controller addImage:savedImage];
[self presentViewController:controller animated:YES completion:Nil];
}
str=#"Text to share";
[controller setInitialText:str];
OR
[controller setInitialText:#"Text to share"];
change your code like this and try...
- (IBAction)facebookPost:(id)sender {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[mySLComposerSheet setInitialText:#"Social Framework test!"];
[mySLComposerSheet addImage:[UIImage imageNamed:#"myImage.png"]];
[mySLComposerSheet addURL:[NSURL URLWithString:#"http://stackoverflow.com"]];
[mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
switch (result) {
case SLComposeViewControllerResultCancelled:
NSLog(#"Post Canceled");
break;
case SLComposeViewControllerResultDone:
NSLog(#"Post Sucessful");
break;
default:
break;
}
}];
[self presentViewController:mySLComposerSheet animated:YES completion:nil];
}
}
Try this........This what I did for my project
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
I have been using this code for twitter posting .
SLComposeViewController *fbController=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewControllerCompletionHandler __block completionHandler=^(SLComposeViewControllerResult result){
[fbController dismissViewControllerAnimated:YES completion:nil];
switch(result){
case SLComposeViewControllerResultCancelled:
default:
{
NSLog(#"Cancelled.....");
}
break;
case SLComposeViewControllerResultDone:
{
NSLog(#"Posted....");
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:#"Success"
message:#"Posted Successfully"
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
break;
}};
[fbController addImage:[UIImage imageNamed:#"1.jpg"]];
[fbController setInitialText:#"Check out this article."];
//[fbController addURL:[NSURL URLWithString:#"http://soulwithmobiletechnology.blogspot.com/"]];
[fbController setCompletionHandler:completionHandler];
[self presentViewController:fbController animated:YES completion:nil];
}
If the user doesn't setup the twitter account it is displaying the alert which is having the setting and cancel buttons . But it is not displaying the alert in the Device? Could any one help me please . Thanks in advance .
The same thing happens with Facebook sharing. Remove the test:
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
If the user's Twitter account isn't already set up in iOS 6, the above test will evaluate to false and none of the sharing code will execute.
Instead, if you skip the check and try to present the SLComposeViewController anyway, iOS will prompt the user to set up their Twitter account.
BOOL canCompose= [SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter];
if (canCompose) {
SLComposeViewController *fbCompose=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[fbCompose setInitialText:addressLabel.text];
[self presentViewController:fbCompose animated:YES completion:nil];
}
once try this code instead of using completionHandler
Follow this tutorial. here open the alert.
http://www.appcoda.com/ios-programming-101-integrate-twitter-and-facebook-sharing-in-ios-6/
- (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];
}}
I was wondering if I need to create a facebook app to do a share on facebook.
I don't want the user to actually login or something like this.
As I see in the facebook docs it says that the prerequisite is to "make sure you already set up Facebook Login". I wanted to know if this is really needed or is something I can by pass, since the user is already logged in on their native facebook app.
I think you are talking about to store id and password of facebook.
you should do it from settings... and also you can check by logic that facebook id and password is entered or not.. if not then session will go for login page otherwise it ll just share the perticular thing.
Hope this Helps you...
Here is what I was talking about:
#pragma mark - Share
- (void)sharingStatus {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
NSLog(#"service available");
self.shareButton.enabled = YES;
self.shareButton.alpha = 1.0f;
} else {
self.shareButton.enabled = NO;
self.shareButton.alpha = 0.5f;
}
}
- (IBAction)facebookPost:(id)sender {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
NSString *shareText = #"This is my share post!";
[mySLComposerSheet setInitialText:shareText];
[mySLComposerSheet addImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:self.imageURL]]];
[mySLComposerSheet addURL:[NSURL URLWithString:#"http://yourURL.com"]];
[mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
switch (result) {
case SLComposeViewControllerResultCancelled:
NSLog(#"Post Canceled");
break;
case SLComposeViewControllerResultDone:
NSLog(#"Post Sucessful");
break;
default:
break;
}
}];
[self presentViewController:mySLComposerSheet animated:YES completion:nil];
}
}