I have used a native post dialog and I am passing an URL to the method that actually displays the dialog.The URL actually gets posted to the Facebook as needed.But I don't want this URL to be shown in post dialog, because if the user modifies it my mistake then some wrong text gets posted.Is there anyway hiding the URL in dialog. I am using the method presentShareDialogModallyFrom:initialText:image:url:handler: to present the native post dialog.
Unfortunately, you don't show any code so we don't know how you pass the URL. You probably use the setInitialText: method, whereas you need the addURL: method.
SLComposeViewController *facebookController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[facebookController setInitialText:self.titel];
[facebookController addURL:[NSURL URLWithString:self.guid]];
[self presentViewController:facebookController animated:YES completion:nil];
Facebook native share, you have to implements Accounts Framework in to your app
In your framwork you have to Add: Social.framework
In your File .h add:
#import "Social/Social.h"
#interface UIViewController {
SLComposeViewController *FBCompose;
}
In your file .m under a IBAction add:
- (IBAction)facebook:(id)sender {
NSData* imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:#"imageURL"]];
UIImage* image = [[UIImage alloc] initWithData:imageData];
//----here you can get pragmaticaly a part of yout text
NSString *mutableArry = (self.myMutableDictionay)[#"string"];
FBCompose = [[SLComposeViewController alloc]init];
FBCompose = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[FBCompose setInitialText:[NSString stringWithFormat:#"Ishare on FB %# from MyApp App", mutableArry]];
[FBCompose addImage:image];
[FBCompose addURL:[NSURL URLWithString:#"http://Link of my app or get the link by myMutableDictionay"]];
[self presentViewController:FBCompose animated:YES completion:NULL];
}
Edit my post because is incomplete sorry.
Hope this help you ;)
Related
I am creating a SLComposeViewController of type SLServiceTypeTwitter and I'm adding an url and text to it. However, the text is not shown, only the url.
Does anybody know why SLComposeViewController's setInitialText is not working on Twitter in iOS 11?
Here is a snippet of my code:
SLComposeViewController *twPostSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[twPostSheet setInitialText:copy];
[twPostSheet addURL:[NSURL URLWithString:url]];
UIViewController *controller = RCTPresentedViewController();
twPostSheet.completionHandler = ^(SLComposeViewControllerResult result) {
// Shared with success
};
[controller presentViewController:twPostSheet animated:YES completion:nil];
This behaviour is intended. You should use Twitter iOS kit. With it you can share Tweets with text, URLs, photos and video. The same goes for Facebook share.
I'm looking for a drop in solution to add a Facebook and Twitter share button option to my app. I've googled this of course, and found shareKit but it's non-ARC so just throws lots of errors, which is of no use to me. Any other options? they need to be ARC compatible.
I want a SDK that I can drop in, throw in the App ID's and be done.
If you want simple sharing, the following can be used for Twitter and Facebook:
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
SLComposeViewController *slComposeViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[slComposeViewController setInitialText:#"Your text"];
[slComposeViewController addImage:[UIImage imageNamed:#"NameOfImage"]];
[self presentViewController:slComposeViewController animated:YES completion:nil];
} else {
//Show alert or in some way handle the fact that the device does not support this feature
}
For Facebook, simply replace SLServiceTypeTwitter with SLServiceTypeFacebook. The "Social" framework must be imported :-)
You can use UIActivityViewController:
NSArray * activityItems = activityItems = #[#"title", [NSURL URLWithString:#"urlstring"]];
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
[self presentViewController:activityController animated:YES completion:nil];
References : https://developer.apple.com/library/ios/documentation/uikit/reference/UIActivityViewController_Class/Reference/Reference.html
Yes use the native iOS sharing dialog: UIActivityViewController
I need to implement a "share as..." function in iOS.
For example a button names "share as..." and popup a dialog which includes items like Email, SMS, Facebook, Twitter.
I wonder if there have a standard dialog do this job.
After searching, I found a way seems quite "standard" way in iOS6 by using UIActivityViewController.
Following is the description from developer.apple.com:
The UIActivityViewController class is a standard view controller that you can use to offer various services from your application. The system provides several standard services, such as copying items to the pasteboard, posting content to social media sites, sending items via email or SMS, and more. Apps can also define custom services.
And following is a dialog I managed to produce by using UIActivityViewController
And following is the source code I use:
NSArray *activityItems = [NSArray arrayWithObjects: share_text.text, share_image.image , nil];
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
[self presentViewController:activityController animated:YES completion:nil];
In your ViewController.m :
NSString *message = #"The Flyer http://flyerdream.tumblr.com";
UIImage *image = [UIImage imageNamed:#"flyer"];
NSArray *arrayOfActivityItems = [NSArray arrayWithObjects:message, image, nil];
UIActivityViewController *activityVC = [[UIActivityViewController alloc]
initWithActivityItems:arrayOfActivityItems applicationActivities:nil];
[self.navigationController presentViewController:activityVC animated:YES completion:nil];
After using UIActivityViewController, I believe it is a much better solution than what I've posted below. I've left my answer because the individual sharing methods may be of use to someone.
This is how I've implemented share features in my projects:
Email: Use MFMailComposeViewController. See documentation here: http://developer.apple.com/library/ios/#documentation/MessageUI/Reference/MFMailComposeViewController_class/Reference/Reference.html
Facebook & Twitter: Use SLComposeViewController. See documentation here: http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Reference/SLComposeViewController_Class/Reference/Reference.html
Example:
// prepare and present SLComposeViewController if service is available
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *socialPost = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[socialPost setInitialText:#"TEXT FOR POST"];
[socialPost addImage:[UIImage imageNamed:#"yourImage.png"]];
[self presentViewController:socialPost animated:YES completion:nil];
}
// set up a completion handler
[socialPost setCompletionHandler:^(SLComposeViewControllerResult result) {
switch (result) {
case SLComposeViewControllerResultDone:
// post was completed
break;
case SLComposeViewControllerResultCancelled:
// post was cancelled
break;
default:
break;
}
}
Note: If you want to post for Twitter, replace SLServiceTypeFacebook with SLServiceTypeTwitter in the code sample above.
I have done all steps that are explained here: https://developers.facebook.com/docs/getting-started/facebook-sdk-for-ios/3.1/
I have tested the demo projects and fail the same as on my project. (you can test it on HelloFacebookSample project).
When you don't have any Facebook account configured, you can't share something on facebook, or upload an image etc, (the same as twitter framework). So the frameworks shows you a message that tells this:
There are no Facebook accounts configured. You can add or create a Facebook account in Settings.
You click on settings but the only thing that happends is that this dialog is hided, but the framework doesn't open the Settings tab (as work on for example on the twitter framework).
Does anyone know how to solve this problem?
Thanks in advance.
Please use SLComposeViewController class for Facebook sharing, setting button work for you.
if([SLComposeViewController class])
{
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller setInitialText:text];
[controller addURL:[NSURL URLWithString:encod]];
[self presentViewController:controller animated:YES completion:Nil];
//[message release];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result)
{
NSString *output= nil;
switch (result)
{
case SLComposeViewControllerResultCancelled:
output= #"Action Cancelled";
break;
case SLComposeViewControllerResultDone:
output= #"Post Succesfull";
[self displayText:#"done"];
break;
default:
break;
}
};
controller.completionHandler =myBlock;
}
This code is working for me
Why dont u use UIActivityViewController ?
iOS 6 have the best support with UIActivityViewController
UIActivityViewController *ActivityView = [[UIActivityViewController alloc] initWithActivityItems:Items applicationActivities:nil];
Best Integration for Facebook, Twitter and sms Service
I am trying to integrate the tweet sheet from the twitter framework. I already got it working on my iPad but when I use the exact same code on my iPod I get a problem.
Everything is fine, I can open the tweet sheet I can type a tweet but when I want to cancel or send a tweet the buttons don't work?
I also noticed that I can still touch the screen behind the tweet sheet. Has anybody got an idea how to set the tweet sheet as the view to operate in? I thought presentModalViewController did that...
//Create the tweet sheet
TWTweetComposeViewController *tweetSheet = [[TWTweetComposeViewController alloc] init];
//Customize the tweet sheet here
//Add a tweet message
[tweetSheet setInitialText:#"text"];
//Add an image
NSString* path = [documentsDirectory stringByAppendingPathComponent:
[NSString stringWithString: #"pngImage.png"] ];
UIImage* content = [UIImage imageWithContentsOfFile:path];
[tweetSheet addImage:content];
//Add a link
//Don't worry, Twitter will handle turning this into a t.co link
[tweetSheet addURL:[NSURL URLWithString:#"urlLink"]];
//Set a blocking handler for the tweet sheet
tweetSheet.completionHandler = ^(TWTweetComposeViewControllerResult result){
[self dismissModalViewControllerAnimated:YES];
};
//Show the tweet sheet!
[self presentModalViewController:tweetSheet animated:YES];