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.
What I am trying to do and it doesn't work is the following: post an image of my choise and also an url to facebook using the built in facebook sharer, the problem is that it doesn't work to upload both, it's either picture + text and works nice or url + text and works nice, but when I combine them text+picture+url it gets the picture from the url and not my uploaded pic. Any suggestions? I am doing this on iOS9
UIImage *tableViewScreenshot = [tblFeed screenshotOfCellAtIndexPath:idx];
SLComposeViewController *fbSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[fbSheet setInitialText:#"I need your vote"];
[fbSheet addURL:[NSURL URLWithString:str]];
[fbSheet addImage:tableViewScreenshot];
The problem is that Facebook has changed some policies and by this you can't have a text or an image present as a default. That's why you're not seeing the text and photo. Here are 2 scenarios one with Facebook app installed and another one without Facebook app installed. The below one is when the Facebook app is already installed on the device.
And this one is when the Facebook app is not installed on the device
And this is my code:
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller addURL:[NSURL URLWithString:#"https://www.google.com"]];
[controller addImage:[UIImage imageNamed:#"icon_circle"]];
[controller setInitialText:#"Bhavuk you're great!"];
[self presentViewController:controller animated:YES completion:nil];
So If you want to share everything, better use FB SDK.
So it seems at the moment there is no solution for this and we should find a workaround for it, maybe uploading everything first a picture to an url and then use fb sdk to point to a picture from that url + the link as an offline pic doesn't seem to work unfortunately.
Unfortunately, the problem remains even on iOS 10. An easy workaround is simply drop the URL, for example:
SLComposeViewController *fbSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[fbSheet setInitialText:#"I need your vote"];
[fbSheet addImage:tableViewScreenshot];
It's not a direct answer to the OP but in case of what you only care is showing text and image while sharing something, here is a possible solution:
If the image and the text that you want to show within your SlComposeView is the same as the information that exist within the web site that you are going to share; you don't need to do anything special at the iOS side at all.
If you are the one who also created the web page that you're sharing URL of, should you have proper Open Graph META Tags at the page, SLComposeView of type Facebook will show image and text which were set at the webpage within your app automagically.
For some information about Facebook Open Graph Markup; see https://developers.facebook.com/docs/sharing/webmasters/#markup
I have had facebook sharing working fine in my ios app when fb not install. and i have installed fb to use the latest api (4.7.x) and now sharing doesnt work at all. I check that I have publish_actions permission (which I do prior to this method being called, I have 'expicitly shared' checked in open graph settings, action types, capabilities. I am validating the content (I dont get an error) and have a delegate, none of its methods get called.
-(void)shareWithFacebook:(NSString *)message
{
if ([[FBSDKAccessToken currentAccessToken] hasGranted:#"publish_actions"])
{
NIDINFO(#"Facebook sharing has publish_actions permission");
}
else
{
FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
[loginManager logInWithPublishPermissions:#[#"publish_actions"]
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
{
NIDERROR(#"Facebook sharing getting publish_actions permission failed: %#", error);
}
];
}
NSMutableDictionary *properties = [NSMutableDictionary dictionaryWithDictionary: #{
#"og:type": #"article",
#"og:title": #"Bloc",
#"og:description": message,
#"og:url": #"http://getonbloc.com/download"
}];
FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties];
// Create the action
FBSDKShareOpenGraphAction *action = [FBSDKShareOpenGraphAction actionWithType:#"mynamespace:Share" object:object key:#"article"];
[action setString:#"true" forKey:#"fb:explicitly_shared"];
// Create the content
FBSDKShareOpenGraphContent *content = [[FBSDKShareOpenGraphContent alloc] init];
content.action = action;
content.previewPropertyName = #"article";
// Share the content
FBSDKShareAPI *shareAPI = [[FBSDKShareAPI alloc] init];
shareAPI.shareContent = content;
shareAPI.delegate = self;
NSError *error;
if([shareAPI validateWithError:&error] == NO)
{
NIDERROR(#"Facebook sharing content failed: %#", error);
}
[shareAPI share];
}
#pragma mark - FBSDKSharingDelegate
- (void) sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results
{
NIDINFO(#"Facebook sharing completed: %#", results);
}
- (void) sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error
{
NIDERROR(#"Facebook sharing failed: %#", error);
}
- (void) sharerDidCancel:(id<FBSDKSharing>)sharer
{
NIDINFO(#"Facebook sharing cancelled.");
}
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 ?
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];
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.