'invalidationHandler called' error when posting on twitter - twitter

I am trying to post on Twitter from my app, but I keep on getting the following error in the log
LaunchServices: invalidationHandler called
Below is my method for posting on Twitter. This method is in a TwitterViewController class which inherits for UIViewController
-(void)tweetHighscore {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:#"Tweeting from my own app! :)"];
[self presentViewController:tweetSheet animated:YES completion:nil];
CCLOG(#"it's working okay");
}
}
EDIT:
I set a breakpoint and it seems like presentViewController:animated:completion: is causing the invalidationHandler.

Related

Trying to dismiss View Controller that presents SLComposeViewController after user posts to FB in iOS

I am presenting an SLComposeViewController to post to Facebook in my app. The user is able to dismiss this View Controller in one of two ways: either by posting their post to Facebook, or by pressing "cancel". When the user presses "cancel", the SLComposeViewController is dismissed, and the user is returned to the presenting View Controller that is behind it.
However, what I would like to do is if the user presses "post", then I want the presenting View Controller to ALSO be dismissed after the SLComposeViewController is dismissed (i.e. in the SLComposeViewControllerResultDone case). My problem is that I am not sure how to do this. I realize that I would use the completion handler for this, but I am stuck here. Here is the code that I have which presents the SLComposeViewController:
SLComposeViewController *fbSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[fbSheet setInitialText:initialText];
[fbSheet addImage:myImage];
SLComposeViewControllerCompletionHandler __block completionHandler=^(SLComposeViewControllerResult result) {
switch(result){
case SLComposeViewControllerResultCancelled:
default:
{
NSLog(#"Cancelled.....");
}
break;
case SLComposeViewControllerResultDone:
{
NSLog(#"Posted....");
}
break;
}
};
[fbSheet setCompletionHandler:completionHandler];
[self presentViewController:fbSheet animated:YES completion:nil];
With the completion handler above, I get the NSLog outputs as expected. However,
Can anyone see what it is I'm doing wrong? As I've pointed out, I need the dismissal of the presenting View Controller to occur ONLY if the user "posts" to Facebook, but NOT when they cancel.
You could simply dismiss the presenting view controller in SLComposeViewControllerResultDone part of completionHandler as below:
dispatch_async(dispatch_get_main_queue(), ^{
[self dismissViewControllerAnimated:YES completion:nil];
});
If you are supporting iOS 6, then you need to dismiss the SLComposeViewController first.
you don't need to dismiss ViewController in the completion handler, it will be handled when you press cancel button
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController * fbSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller setInitialText:initialText];
[fbSheet addImage:myImage];
[self presentViewController:controller animated:YES completion:Nil];
}

iOS native Facebook share, link preview not working?

I need to share the URL to Facebook from my app, and I am using SLComposeViewController for same. Here is the code I am using :-
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *facebookController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[facebookController setInitialText:text];
[facebookController addURL:url];
[facebookController addImage:image];
[controller presentViewController:facebookController animated:YES completion:nil];
}
Here is the URL, I am using :-
http://www.erosnow.com/#!/movie/watch/1004607/ferrari-ki-sawaari/6095229/ferrari-ki-sawaari
The problem is, it doesn't show link preview. But when I copy paste the URL in Facebook "Whats your mind" segment, it do show the link preview. Any help

Performing Segue After Sharing - Objective-C (Xcode)

I have a twitter sharing view controller that opens in front of one of my view controllers. I make the twitter view like this:
if ([shareOption isEqual: #"Tweet"]) {
SLComposeViewController *tweetSheet = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:combined];
[tweetSheet addImage:capturedScreen];
[self presentViewController:tweetSheet animated:YES completion:nil];
}
I have this line of code to switch to my next view controller:
[self performSegueWithIdentifier: #"goBack" sender: self];
How can I call this line after the user finishes tweeting? I would also like this line to execute if the user decides to cancel their tweet.
EDIT
if ([shareOption isEqual: #"Tweet"]) {
SLComposeViewController *tweetSheet = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:combined];
[tweetSheet addImage:capturedScreen];
iJustShared = #"YES";
[self presentViewController:tweetSheet animated:YES completion:nil];
[tweetSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
[self performSegueWithIdentifier: #"goBack" sender: self];
}];
}
You need to have that line in your tweet controller, and if you want that segue to go back to the previous controller, you'll need to do dismissViewControllerAnimated:completion.
But, since you're using SLComposeViewcontroller and you are not subclassing it, you must use a handler by setting its completion handler:
[tweetSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
//actions!
}];
https://developer.apple.com/library/ios/documentation/NetworkingInternet/Reference/SLComposeViewController_Class/Reference/Reference.html#//apple_ref/occ/instp/SLComposeViewController/completionHandler

Default Alert for Social View is not shown in ios 7

I implemented the Social framework in my app to post on facebook. It works fine.
But if there is no account in settings, then the Defalut alert is not come in IOS 7.
In IOS 6, it will come as follow.
Is this default Problem in ios 7?
My code is as follow:
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller setInitialText:#"First post from my iPhone app"];
[controller addURL:[NSURL URLWithString:#"http://www.appcoda.com"]];
[controller addImage:[UIImage imageNamed:#"iconTemp.png"]];
[self presentViewController:controller animated:YES completion:nil];
}
To make it work in iOS 7, just remove the following line from your code and it will work fine.
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {

How to add url for SLComposeViewController in iOS7?

In my app i'm using SLComposeViewController to send tweets. I'm also calling its method addURL: like this:
[tweetSheet addURL:[NSURL URLWithString:#"http://itunes.com/apps/MyAppName"]];
and it works fine in iOS 6, but in iOS 7 it opens iTunesStore right after being presented on the screen. How do i fix it?
UPDATE:
if ([SLComposeViewController isAvailableForServiceType:network])
{
AppController *appController = (AppController *)[[UIApplication sharedApplication] delegate];
MyNavigationController *navController = appController.navController;
UIViewController *currentController = [[navController viewControllers] lastObject];
SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:network];
[tweetSheet setInitialText:text];
[tweetSheet addImage:[UIImage imageNamed:temp_character]];
[tweetSheet addURL:[NSURL URLWithString:#"http://itunes.com/apps/MyAppName"]];
tweetSheet.completionHandler = ^(SLComposeViewControllerResult result){
[currentController dismissViewControllerAnimated:YES completion:nil];
if (result == SLComposeViewControllerResultDone)
[[NSNotificationCenter defaultCenter] postNotificationName:HC_TWEET_SENT_NOTIFICATION object:nil];
};
[currentController presentViewController:tweetSheet animated:YES completion:nil];
}
Your custom socialIntegration class has a bug in it. It only returns a SLComposeViewController if Facebook is available on the device. If it isn't, it returns nothing.
However, you don't test for this when you actually call it:
SLComposeViewController * faceSheet=[self.socialIntegration showFacebook:#"text" andImage:nil andLink:#"link" andView:self];
dispatch_sync(dispatch_get_main_queue(), ^{
//[self netConnectionTrue:cell Connected:answer];
//[tempAlertView show];
[self presentViewController:faceSheet animated:YES completion:NO];
});
...you're not checking to see if faceSheet is nil. So if there's no Facebook account you call presentViewController with a nil object, which triggers the error you're seeing.
The reason you are seeing this on iOS 7 is your linked FB accounts probably got reset, but it was probably a source of crashes for your users on iOS 6 as well.

Resources