Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
I want to connect Facebook and Twitter account with my iOS app. I am looking for the code which checks if accounts is there in settings or not. If it's there it takes for login with same account and if it's not then asks user to add account in settings.
I tried couple of things but really not working. If anyone needs my code, then let me know i will post it on pastebin.
Add Twitter and Social Framework in your Project and import in your class file like
#import <Social/Social.h>
#import <Twitter/Twitter.h>
For Facebook
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
NSData *aImgdata=[[NSUserDefaults standardUserDefaults]objectForKey:#"EditImage"];
if (aImgdata) {
UIImage *aImage=[UIImage imageWithData:aImgdata];
[controller addImage:aImage];
}
controller.completionHandler = ^(SLComposeViewControllerResult result) {
if(result == SLComposeViewControllerResultDone) {
}
[self dismissViewControllerAnimated:YES completion:nil];
};
[self presentViewController:controller animated:YES completion:Nil];
}
else
{
[self ShowAlertView: #"You can't share on facebook right now, make sure your device has an internet connection and you have at least one Facebook account setup"];
}
For Twitter
if([TWTweetComposeViewController canSendTweet]) {
{
TWTweetComposeViewController *tweetViewController = [[TWTweetComposeViewController alloc] init];
NSData *aImgdata=[[NSUserDefaults standardUserDefaults]objectForKey:#"EditImage"];
if (aImgdata) {
UIImage *aImage=[UIImage imageWithData:aImgdata];
[tweetViewController addImage:aImage];
}
tweetViewController.completionHandler = ^(TWTweetComposeViewControllerResult result) {
if(result == TWTweetComposeViewControllerResultDone) {
[self ShowAlertView: #"Tweet Has been Shared"];
}
[[AppDelegate sharedInstance]showActivity:NO];
[self dismissViewControllerAnimated:YES completion:nil];
};
[self presentViewController:tweetViewController animated:YES completion:nil];
}
} else {
[self ShowAlertView: #"You can't send a tweet right now, make sure your device has an internet connection and you have at least one Twitter account setup"];
}
Add Social Framework to you project and import in your class
#import <Social/Social.h>
For Facebook
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller addImage:UIImage];
controller.completionHandler = ^(SLComposeViewControllerResult result) {
if(result == SLComposeViewControllerResultDone) {
}
[self dismissViewControllerAnimated:YES completion:nil];
};
[self presentViewController:controller animated:YES completion:Nil];
}
else
{
//Show Alert: No Facebook Account in Settings Page
}
For Twitter
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[controller addUrl:NSURL];
controller.completionHandler = ^(SLComposeViewControllerResult result) {
if(result == SLComposeViewControllerResultDone) {
}
[self dismissViewControllerAnimated:YES completion:nil];
};
[self presentViewController:controller animated:YES completion:Nil];
}
else
{
//Show Alert: No Twitter Account in Settings Page
}
To check if you can share with Facebook or Twitter, use:
[SLComposeViewController isAvailableForServiceType:serviceType]
Where serviceType can be any of the SLServiceTypes such as, SLServiceTypeFacebook and SLServiceTypeTwitter
This will basically check if they have those services natively connected in their settings. I don't think you can ask the user to add it in their settings. Most of the time, a particular sharing option just won't show up if it is not available like on a UIActionSheet.
My guess would be that you can use the SLComposeViewController to check for a connected account and if not connected, use the appropriate SDK to connect their account with your iOS app.
Related
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'm looking to add functionality that when an event happens on my app, it will post to my facebook timeline. That said, I'm trying to get it to look very similar to how when you post a youtube video to the timeline where there is a thumbnail image to the left and a title and subtitle next to it.
Anyone have any ideas how I can accomplish this?
You can't make a post automatically from code, but you can open a system window with predefined message and image attachment.
Sample code:
- (BOOL)postToFacebook:(NSString*)title andDescription:(NSString*)description {
UIWindow *frontWindow = [[UIApplication sharedApplication] keyWindow];
UIViewController *vc = [frontWindow rootViewController];
BOOL success = NO;
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result) {
if (result == SLComposeViewControllerResultCancelled) {
} else {
}
[controller dismissViewControllerAnimated:YES completion:Nil];
};
controller.completionHandler = myBlock;
[controller setTitle:title];
[controller setInitialText:description];
[controller addURL:[NSURL URLWithString:#"http://example.com"]];
[controller addImage:[UIImage imageNamed:#"sampleImage.png"]];
[vc presentViewController:controller animated:YES completion:^{
}];
success = YES;
}
return success;
}
Remember to add two frameworks:
Social.framework
Accounts.framework
I am pretty new at incorporating Facebook into iOS apps. I have read 3 books, studied the Facebook examples, and studies the Facebook tutorials, and I don't understand Facebook integration. I understand how to register the app with Facebook, but what I don't understand is the code to post text and a picture to a user's news feed. I have tried to understand Facebook's tutorials, but they are all based on Xcode and iOS versions which are not current. Facebook's tutorials are also not consistent (e.g., the login tutorial does not match variables with the posting tutorial, etc.). I do understand how to add text to "initialText", but it's against Facebook policy to provide default text in this variable. Can anyone explain how to publish text and a picture to a user's news feed in Xcode?
Thanx!
Have you tried this one?
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultCancelled) {
NSLog(#"ResultCancelled");
} else
{
NSLog(#"ResultSuccess");
}
[controller dismissViewControllerAnimated:YES completion:Nil];
};
controller.completionHandler =myBlock;
[controller setInitialText:#"Learn iOS6 Social Framework integration"];
[controller addURL:[NSURL URLWithString:#"http://google.com"]];
[controller addImage:[UIImage imageNamed:#"myimage.jpeg"]];
[self presentViewController:controller animated:YES completion:Nil];
}
else{
//NSLog(#"UnAvailable");
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:#"Facebook"
message:[NSStringstringWithFormat:#"The application cannot post message at the moment. Please login under setting section with your Facebook account."]
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
import social framework in your project.
- (void)ShareOnFB
{
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultCancelled) {
NSLog(#"Cancelled");
} else
{
NSLog(#"Done");
//Adding the Text to the facebook post value from iOS
}
[controller dismissViewControllerAnimated:YES completion:Nil];
};
controller.completionHandler =myBlock;
NSString *fb=[NSString stringWithFormat:#"you can add your text hereand change it as and when needed"];
[controller setInitialText:fb];
//Adding the Image to the facebook post value from iOS
[controller addImage:yourImageView.image];
[self presentViewController:controller animated:YES completion:Nil];
}
Im trying to add caption/meta data from the link that is attached from the the NSURL.
I followed this article: http://www.mobile.safilsunny.com/integrating-facebook-ios-6/
There are a picture attached to the article at the bottom, that includes the meta data from its link. ( Windows Phone 8 tutorials... etc).
When sharing links on Facebook web, it will automatically give you this meta data so my question is how can i achieve this from iOS?
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultCancelled) {
NSLog(#"Cancelled");
} else
{
NSLog(#"Done");
}
[controller dismissViewControllerAnimated:YES completion:Nil];
};
controller.completionHandler =myBlock;
[controller setInitialText:#"google.se"];
[controller addURL:[NSURL URLWithString:#"http://www.google.se"]];
[controller addImage:[UIImage imageNamed:#"icon.png"]];
[self presentViewController:controller animated:YES completion:Nil];
}
else{
NSLog(#"UnAvailable");
}
EDIT #1: I see that the Digg app do this.
Use Facebook SDK it is not possible now using SLComposeViewController