I've integrated Fabric Framework in my project, now i want to compose my image by using Twitter App installed from App Store, but twitter use SLComposeViewController UI of iOS, so i don't know what is different between using SLComposeViewController and Twitter SDK ?.
When i use Facebook SDK, sharing will use facebook app, with Twitter it not.
I use this code to compose Image.
TWTRComposer *composer = [[TWTRComposer alloc] init];
[composer setText:#"just setting up my Fabric"];
[composer setImage:[UIImage imageNamed:#"fabric"]];
[composer showWithCompletion:^(TWTRComposerResult result) {
if (result == TWTRComposerResultCancelled) {
NSLog(#"Tweet composition cancelled");
}
else {
NSLog(#"Sending Tweet!");
}
}];
Related
I basically want the user to share something from my app to twitter. I was exploring the different methods possible and found SLComposeViewController but it is deprecated. Support for twitterKit has also been officially stopped by twitter. One possible way to do so seems to be like given in the answers in this post. Is there some other better way to do so? I would prefer if the user stays in the app itself (something similar to sharesheet for fb). Thanks!
You can use twitter-kit-ios.
For posting a tweet sample code from documentation would be following
Objective-c
// Objective-C
TWTRComposer *composer = [[TWTRComposer alloc] init];
[composer setText:#"just setting up my Twitter Kit"];
[composer setImage:[UIImage imageNamed:#"twitterkit"]];
// Called from a UIViewController
[composer showFromViewController:self completion:^(TWTRComposerResult result) {
if (result == TWTRComposerResultCancelled) {
NSLog(#"Tweet composition cancelled");
}
else {
NSLog(#"Sending Tweet!");
}
}];
Swift
// Swift
let composer = TWTRComposer()
composer.setText("just setting up my Twitter Kit")
composer.setImage(UIImage(named: "twitterkit"))
// Called from a UIViewController
composer.show(from: self.navigationController!) { (result in
if (result == .done) {
print("Successfully composed Tweet")
} else {
print("Cancelled composing")
}
}
Straight from the discontinuing blog post you can use, new api endpoints.
In my project, I always use SLComposeViewController to share contents with third-party apps, but now, when I update my iPhone to iOS 11 beta, this no longer works.
The SLComposeViewControllerCompletionHandler always callback SLComposeViewControllerResultCancelled.
Why is this?
I was having problems with regard to the SLComposer in iOS 11. But I just removed the line that checks and apparently the own SDK makes the validacoes to me internally.
Remove this line serves for any SLServiceType:
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
So, develop your logic. In my case:
SLComposeViewController *mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[mySLComposerSheet setInitialText:#"#myInitialTextIsHere"];
[mySLComposerSheet addURL:[NSURL URLWithString:strURL]];
[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];
I hope I have helped!
iOS 11 removed access to 3rd party accounts (such as Facebook and Twitter) through the Settings App. I’m currently struggling with the same thing.
You now must integrate the functionality with the SDK from the 3rd party. Twitter has a migration page here about steps to take:-
https://dev.twitter.com/twitterkit/ios/migrate-social-framework
I’ve yet to find specific instructions about how to migrate other social networks, but it’s safe to say it will require their 3rd party SDK.
No more easy out-the-box social sharing :-(
For iOS 11 this line:
([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
is always returning NO
I replaced it with check if user has Facebook app installed with:
static NSString *const canOpenFacebookURL = #"fbauth2";
+ adding it to LSApplicationQueriesSchemes in plist
-(BOOL)isFacebookAppInstalled {
NSURLComponents *components = [[NSURLComponents alloc] init];
components.scheme = canOpenFacebookURL;
components.path = #"/";
return [[UIApplication sharedApplication]
canOpenURL:components.URL];
}
And then just call SLComposeViewController *composeVC = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
as usual, the same how Matheus Domingos described. But with this check at least you know that user has facebook app installed.
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.");
}
Hi i am using following code to share message using IOS6 native lib
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
SLComposeViewController *mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[mySLComposerSheet setInitialText:#"Good morning all"];
//[mySLComposerSheet addImage:[UIImage imageNamed:#"img1.png"]];
[mySLComposerSheet addURL:[NSURL URLWithString:#"http://www.google.com/"]];
[self.superViewController presentViewController:mySLComposerSheet animated:YES completion:nil];
[mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
NSString *output = #"";
switch (result) {
case SLComposeViewControllerResultCancelled:
output = #"ACtionCancelled";
break;
case SLComposeViewControllerResultDone:
output = #"Post Successfull";
break;
default:
break;
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Facebook Message" message:output delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alert show];
}];
}
it is successfully posted But in my facebook it is showing via IOS but i want to display my application name. I followed all steps when i am creating app id on facebook developer zone
How to change IOS to my application name?
I also tried this code http://www.developers-life.com/facebook-compose-view.html
When using SLComposeViewController you cannot change the "via" name, it will always show "iOS" as the source.
You are required to use the Facebook iOS SDK and set up your own custom compose view instead of using the native SLComposeViewController.
UPDATE
Facebook's 3.5+ SDK offers a number of great solutions, such as the Share Dialog, which uses the native Facebook and open graph.