SLComposeViewController - SLServiceTypeTwitter, addImage issue - twitter

Here is what I am facing using SLComposeViewController to generate a tweet in an iOS app.
First of all this is my code:
- (IBAction)twitButtonHandler:(id)sender
{
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
SLComposeViewController *tweetController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
tweetController.completionHandler=nil;
[tweetController setInitialText:#"Hello this is a tweet."];
if (![tweetController addImage:[UIImage imageNamed:#"MyNicePicture.png"]]) {
NSLog(#"Unable to add the image!");
} else NSLog(#"Add the image OK!");
[self presentViewController:tweetController animated:YES completion:Nil];
} else {
// The device cannot send tweets.
NSLog(#"No Tweet possible!");
return;
}
}
The above code works fine except for the fact that I never see the image in the actual tweet though it always displays the message "Add the image OK!" in the debugger. Can anyone see something wrong in the code? Or tell me where could be a potential problem?

Digging more into the issue on my own made me discover that :
[UIImage imageNamed:#"MyNicePicture.png"]
was returning nil.
From that point everything is explained and the problem has to do with the way I get the UIImage object, not with SLComposeViewController and SLServiceTypeTwitter as I first thought.

Related

Share image to Facebook (IOS app/Objective-C)

pls help. I have not made an update to my app in over a year. Now I tried to add a button to share an image to Facebook. But the button will not don't work. In general, nothing happens after pressing on it. How can I fix it ?
Best regards,
Ivan (yeah yeah my english is poor)
-(void)shareWithFacebook{
NSLog(#"fb");
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
SLComposeViewController *fbSheet = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeFacebook];
[fbSheet setInitialText:#"Document from Docement scanner"];
[fbSheet addImage:self.savedImage];
[self presentViewController:fbSheet animated:YES completion:nil];
}
}

iOS app crashes when displaying SLComposeViewController

Okay, so I have a single view iOS app. Inside the view controller, I have a method attached to a button in the storyboard. Here is the method for when then button is pressed:
- (IBAction)tweetButton:(id)sender {
if ([SLComposeViewController isAvailableForServiceType:#"SLServiceTypeTwitter"]) {
SLComposeViewController *tweetSheet = [[SLComposeViewController alloc] init];
tweetSheet = [SLComposeViewController composeViewControllerForServiceType:#"SLServiceTypeTwitter"];
[tweetSheet setInitialText:#"This is a test."];
[self presentViewController:tweetSheet animated:YES completion:nil];
}
else {
NSLog(#"Twitter not configured.");
}
}
Whenever I press the button in the app, I get a crash with the following error:
2015-07-17 15:57:24.110 Now Playing[425:19583]
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller on target <ViewController: 0x157e4c620>.'
My code follows pretty much every example that I have seen online, so I'm not sure what's up.
You mustn't hard type the service type even if it's taking a NSString, you must use one of the constant instead: SLServiceTypeTwitter, SLServiceTypeFacebook...
Also, composeViewControllerForServiceType: is already doing the alloc/init steps for you, so no need to allocate it before calling this method.
Code fixed:
- (IBAction)tweetButton:(id)sender {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:#"This is a test."];
[self presentViewController:tweetSheet animated:YES completion:nil];
}
else {
NSLog(#"Twitter not configured.");
}
}

What can I do if isAvailableForServiceType method returns NO

What can I do if isAvailableForServiceType method returns NO in case of Twitter, for example?
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
// post message
} else {
// show some additional screen
}
Can I somehow provide the user a standard login / register view or switch him to the iOS settings? If yes, how can I do it?
Thanks in advance.
try this
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
//
} else {
SLComposeViewController *twitterSignInDialog = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[self presentViewController:twitterSignInDialog animated:NO completion:nil];
}

Detecting if Twitter account is set up on iOS 7

I've been following some tutorials on integrating Twitter into my application. Here is what I have so far:
- (IBAction)postToTweeter:(id)sender {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
SLComposeViewController *tweetSheet = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:#"this is a test"];
[self presentViewController:tweetSheet animated:YES completion:nil];
}
}
My storyboard has a button, and when a user taps that button, this is the code that gets called. However, this only works whenever they have a Twitter account setup on their iPhone first. How can I handle the case where a user has not set up a twitter account yet, and show them an alert instructing them to add a Twitter account?
SLComposeViewController has a very handy built-in mechanism, whereby it will offer to send the user to Settings if you instantiate a ComposeViewController when the user hasn't set up / logged into the social-media service in question. To test this, all you need to do is remove the conditional so your code looks like this:
- (IBAction)postToTweeter:(id)sender {
SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:#"this is a test"];
[self presentViewController:tweetSheet animated:YES completion:nil];
}
...and you'll find that iOS will automatically pop up an alert which will take the user through to Settings.
Note that I've found that this doesn't tend to work in the simulator, so it's best to test on a device.

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

Resources