I have the code:
#import <Social/Social.h>
//...
//...
-(void)work {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[controller setInitialText:#"Its example text for Twitter"];
[controller addImage:[UIImage imageNamed:#"automobile"]];
[controller addURL:[NSURL URLWithString:#"http://www.auto.ru"]];
controller.completionHandler = ^(SLComposeViewControllerResult result) {
NSLog(#"*** %#", NSStringFromSelector(_cmd));
};
} else {
NSLog(#"The twitter service is not available");
}
}
but i have warning:
'SLServiceTypeTwitter' is deprecated: first deprecated in iOS 11.0
and log:
...[core] isAvailableForServiceType: for com.apple.social.twitter returning NO
...The twitter service is not available
Hope me please?
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
In my application I used UIActivityViewController to share text in Facebook and Twitter. But how to do different text to share? please help ..thanks in advance
I used this code:
NSString *posturl2=#"twittwrer and facebook ";
UISimpleTextPrintFormatter *printData = [[UISimpleTextPrintFormatter alloc]
initWithText:#"Hi"];
NSArray *Itemsarray = #[posturl2,printData];
UIActivityViewController *activityController = [[UIActivityViewController alloc]initWithActivityItems:Itemsarray applicationActivities:nil];
[self presentViewController:activityController
animated:YES completion:nil];
want like this
Import Social Framework
#import <Social/Social.h>
Then just call
- (void)shareOnFacebookWithText:(NSString *)textToShare {
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller setInitialText:textToShare];
[self presentViewController:controller animated:YES completion:nil];
}
}
- (void)shareOnTwitterWithText:(NSString *)textToShare {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewController *tweetSheet = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:textToShare];
[self presentViewController:tweetSheet animated:YES completion:nil];
}
}
here i have a piece of code
(void)postToTwitter:(id)sender
{
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:#"Great fun to learn iOS programming at softwareWeaver!"];
[self presentViewController:tweetSheet animated:YES completion:nil];
}
}
but what next to do ????
You can use the STTwitter library which makes all of this very very easy:
self.twitter = [STTwitterAPI twitterAPIOSWithFirstAccount];
[_twitter verifyCredentialsWithSuccessBlock:^(NSString *username) {
[_twitter getFollowersForScreenName:username successBlock:^(NSArray *followers) {
NSLog(#"-- %#", followers);
} errorBlock:^(NSError *error) {
//
}];
} errorBlock:^(NSError *error) {
//
}];
I'm building an IOS7 Native app on behalf of a client - its for Fitness Instructors.
The brief requests that the clients can socially share progress updates - which include a link to the instructors site to help promotion, for example - 'Joe ran 3000 miles with the help of Debbie Personal Trainer' and ideally a little pic of the trainer.
I've looked at the SLComposeViewController and can easily create the tweet string but I don't know how to add a URL and image to this - does anyone know if its possible?
Import framework <Twitter/Twitter.h> and <Social/Social.h>.
-(void)sendFacebook:(id)sender {
SLComposeViewController *composeController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[composeController setInitialText:#"look me"];
[composeController addImage:[UIImage imageNamed:#"image.png"]];
[composeController addURL: [NSURL URLWithString:#"http://www.apple.com"]];
[self presentViewController:composeController animated:YES completion:nil];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultCancelled) {
NSLog(#"delete");
} else {
NSLog(#"post");
}
// [composeController dismissViewControllerAnimated:YES completion:Nil];
};
composeController.completionHandler =myBlock;
}
- (void)sendTwitter:(id)sender {
SLComposeViewController *composeController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[composeController setInitialText:#"look me"];
[composeController addImage:[UIImage imageNamed:#"image.png"]];
[composeController addURL: [NSURL URLWithString:
#"http://www.apple.com"]];
[self presentViewController:composeController
animated:YES completion:nil];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultCancelled) {
NSLog(#"delete");
} else {
NSLog(#"post");
}
// [composeController dismissViewControllerAnimated:YES completion:Nil];
};
composeController.completionHandler =myBlock;
}
This is almost the same answer as llario, but follows Apple docs instructions and employs defensive coding with some additional error checking.
#import <Social/Social.h>
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
SLComposeViewController *composeViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
if (composeViewController) {
[composeViewController addImage:[UIImage imageNamed:#"MyImage"]];
[composeViewController addURL:[NSURL URLWithString:#"http://www.google.com"]];
NSString *initialTextString = #"Check out this 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];
}
}