Tweet sheet ios5 presentModalViewController - ios

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];

Related

SLComposeViewController setInitialText not working on Twitter in iOS 11

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.

iOS Twitter reply dialog

I want to add the ability to reply to tweets and would like to use the built-in dialog. Is there any way to do this, or maybe a library that exists for this scenario?
I've tried simply adding #username as the initial text in the dialog, but it doesn't post it as a reply to a particular tweet:
SLComposeViewController* cvc = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
cvc.completionHandler = ^(SLComposeViewControllerResult result) { };
[cvc setInitialText:[NSString stringWithFormat:#"#%#", [self.tweet objectForKey:#"twitter_screen_name"]]];
[controller presentViewController:cvc animated:YES completion:nil];
Is there a solution, or do I need to just manually create a dialog and style it?

iOS6 native facebook share dialog url

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 ;)

iPhone app freezes on presentViewController with SLComposerViewController

I am implementing sharing with Facebook and Twitter - On the simulator both of these work, but on my iPhone 4S running iOS6 the Facebook button freezes the app. The code is the same as it is for the Twitter and functions the same (it hits presentViewController, then the app just stops responding).
The code is as follows:
SLComposeViewController *mulitpartPost = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
// Set the text of the tweet
[mulitpartPost setInitialText:[NSString stringWithFormat:#"I've had a change in weight of "]];
// Add the image to the tweet
if([[NSUserDefaults standardUserDefaults] boolForKey:#"fbProgPicShare"])
[mulitpartPost addImage:[_imgCurrent image]];
mulitpartPost.completionHandler = ^(SLComposeViewControllerResult res){
[self dismissViewControllerAnimated:YES completion:nil];
};
// Display the tweet sheet to the user
[self presentViewController:mulitpartPost animated:YES completion:nil];
isAvailableForServiceType also returns YES if I put that into the code - so I cannot think of why this would freeze when the Twitter button works on the phone. Both Twitter and FB accounts are setup.
Any help would be appreciated.
Strange Fix
It seems to work consistantly now that I do
// Display the tweet sheet to the user
if(!(multipartPost == nil))
[self presentViewController:mulitpartPost animated:YES completion:nil];
Otherwise it still freezes.

standard way to implement share as function

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.

Resources