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]];
Related
Is there a way to check if the user is signed in in the device settings?
If yes, how?
Also, is there a way to direct the user to the device settings directly to the Facebook account tab? If yes, how?
The thing is, I want to detect if the user is already logged in in the device settings. If yes, then I will let the user share. If not, I want to redirect the user to the device settings in the fb tab and let him decide if he wants to log in or not.
ACAccountType *facebookAccountType;
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
facebookAccountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSArray *facebookAccounts = [accountStore accountsWithAccountType:facebookAccountType];
if([SLComposeViewController instanceMethodForSelector:#selector(isAvailableForServiceType)] != nil)
{
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
SLComposeViewController *composeViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[composeViewController setInitialText:#"Hello"];
[composeViewController setCompletionHandler:^(SLComposeViewControllerResult result) {
switch (result) {
case SLComposeViewControllerResultCancelled:
[UIAlertView showAlertViewWithTitle:APPNAME message:#"Facebook sharing canceled!!"];
break;
case SLComposeViewControllerResultDone:
[UIAlertView showAlertViewWithTitle:APPNAME message:#"Successfully posted on Facebook."];
break;
default:
break;
}
}];
[[self.window rootViewController] presentViewController:composeViewController animated:YES completion:nil];
}
I have made a random fact generator and was wondering if i could make the initial text in a tweet from the app the same as whatever the label (which is where the fact i going to be displayed when the user pushes a button) says. Help would be greatly appreciated, and i am new semi new to coding but just really need help on this one part. If you need more info about what i am asking just leave a comment. thanks
This is the code that i would use to generate the tweet (if i knew how to make the initial text a variable) What i have with stars around it is what i want to have changed :
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
SLComposeViewController *twitter = [[SLComposeViewController alloc] init];
twitter = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[twitter setInitialText:[NSString stringWithFormat:#"***Say Something***"]];
[self presentViewController:twitter animated:YES completion:nil];
[twitter setCompletionHandler:^(SLComposeViewControllerResult result) {
NSString *output;
switch (result) {
case SLComposeViewControllerResultCancelled:
output = #"Action Cancelled";
break;
case SLComposeViewControllerResultDone:
output = #"Tweet Successful!";
break;
default:
break;
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Twitter" message:output delegate:nil cancelButtonTitle:#"Okay" otherButtonTitles:nil, nil];
[alert show];
}];
}
You should really consider reading the manual. The line itself is pretty self-explanatory:
[twitter setInitialText:[NSString stringWithFormat:#"***Say Something***"]];
Now, all you have to do is change it so that it's sourcing from your label. Assuming your label that you would like to tweet the text from is called factLabel, you'd have to do something like this:
[twitter setInitialText:factLabel.text];
I am working on an app which provides user to share the details of their app into facebook . I have UITableview where it contains the list of author name and when u click on book name it goes to another UITableView where it shows the different book of that author in each TableViewCell. I'm able to display the list in 2nd UITableView .
I wanted to know how to share the author name , book name and the image (2nd tableview details).
I'm showing the code which does that ..
So when the user wants to share the details, he will have to tap on the UIButton which is there in every cell of author UITableView.
didselectatindexpath
NSDictionary *selectedAuthor = nil;
NSArray *sectionArray=[mainIndexDictionary objectForKey:[allKeysArray objectAtIndex:indexPath.section]];
selectedAuthor = [sectionArray objectAtIndex:indexPath.row];
iPath=[[selectedAuthor objectForKey:#"SymptIndexID"] intValue];
NSLog(#"iPath - %d",iPath);
authortitleString=[[selectedAuthor objectForKey:#"authorIndexName"]stringByAppendingString:#" cure!"];
}
bookArray=[objDB customCellData:(NSInteger)iPath];
[self.view bringSubviewToFront:authorView];
[bookTableView scrollRectToVisible:CGRectMake(0.0, 0.0, 320.0,10.0) animated:NO];
[bookTableView reloadData]
;
In ios 6.0
you can achieve as follows (you must add the social framework to your project)
#import <Social/Social.h>
- (void)ShareFacebook
{
SLComposeViewController *fbController=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
SLComposeViewControllerCompletionHandler __block completionHandler=^(SLComposeViewControllerResult result){
[fbController dismissViewControllerAnimated:YES completion:nil];
switch(result){
case SLComposeViewControllerResultCancelled:
default:
{
NSLog(#"Cancelled.....");
// [[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"prefs://"]];
}
break;
case SLComposeViewControllerResultDone:
{
NSLog(#"Posted....");
}
break;
}};
[fbController setInitialText:#"This is My Sample Text"];
[fbController setCompletionHandler:completionHandler];
[self presentViewController:fbController animated:YES completion:nil];
}
else{
UIAlertView *alert = [[[UIAlertView alloc]initWithTitle:#"Sign in!" message:#"Please first Sign In!" delegate:nil cancelButtonTitle:#"ok" otherButtonTitles:nil, nil]autorelease];
[alert show];
}
}
your question is a bit unclear but you can use this code for publishing text and image to Fb considering you have implemented all the others methods of FB ios Api correctly
SBJSON *jsonWriter = [[SBJSON new] autorelease];
NSDictionary* actionLinks = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:
APP_NAME,#"text", fb_app_url,#"href", nil], nil];
NSString *actionLinksStr = [jsonWriter stringWithObject:actionLinks];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
APP_NAME, #"name",
fb_app_url, #"link",
fb_publish_image, #"picture",
APP_NAME, #"name",
#"Awesome APP", #"caption",
[NSString stringWithFormat:#"I am loving it", GAME_NAME], #"description",
#"Get it now!", #"message",
actionLinksStr, #"action_links",
nil];
[self.faceBook dialog:#"stream.publish" andParams:params andDelegate:self];
for further details to implement fb api you can see
How to integrate Facebook into iPhone Appenter link description here
this link shows the parameters allowed while publishing a message
http://developers.facebook.com/docs/howtos/publish-to-feed-ios-sdk/
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.
In my iOS app, I successfully integrated latest facebook framework.
Its working fine if "facebook" app is not on my iphone. If the app is not on my iphone, during authentication, its opening the browser and authenticating properly.
But if the facebook app is there on my iphone, after authentication and when returning to my app, its crashing with following error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SBJsonParser errorTrace]: unrecognized selector sent to instance 0x2d9f60'
I have seen the samples provided by facebook and implemented the same in my app. Can some one point out me what might be the issue?
This is a bit of a stab in the dark but I think you might be calling the method errorTrace on an instance of SBJsonParser :)
What's probably happening is you're calling errorTrace on something that you have released early. Go through the code path triggered when facebook reopens your app and find a call to errorTrace. Set a breakpoint just before it and have a look around to see what's wrong.
If you want only share something in iOS 6.0 so you use social and account framework and do the job by iPhone internal login using following code
-(void)facebook_Share_in_IOS6.0{
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];
[self presentViewController:mySLComposerSheet animated:YES completion:nil];
}else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Attention" message:#"First Set your facebook account. To post your answer to facebook" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}
[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];
}];
}