I'm in the process of changing my app for iOS6 and iPhone use, I can't seem to figure out why when I post from Twitter using the new Social framework I have to press 'Cancel' twice to close, anybody else have this issue or a fix? Here is the code for the button.
- (IBAction)twitterPost:(id)sender
{
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
mySLComposerSheet = [[SLComposeViewController alloc] init];
mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[mySLComposerSheet setInitialText:[NSString stringWithFormat:#"This is my tweet, hello!",mySLComposerSheet.serviceType]];
[self presentViewController:mySLComposerSheet animated:YES completion:nil];
}
[mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
NSLog(#"dfsdf");
switch (result) {
case SLComposeViewControllerResultCancelled:
break;
case SLComposeViewControllerResultDone:
break;
default:
break;
}
}];
}
If your using the mySLComposerSheet this works great...
[mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
[mySLComposerSheet dismissViewControllerAnimated:YES completion:nil];
My experience with SLComposeViewController is that twitter and weibo controllers need to be dismissed manually while the facebook controller seems to be better behaved.
If I don't dismissViewControllerAnimated myself, tapping the "Send" button will send the tweet or weibo posting but I'll be left with what seems to be an invisible view over my own view. Thus I can no longer interact with my app.
I don't know why my app is working like this... Interestingly, the completionHandler for cancel gets called just once. The second tap dismisses the view controller.
+ (void) shareText:(NSString*)text image:(UIImage*)image social:(NSString*)service url:(NSString*)url
{
SLComposeViewController* controller = [SLComposeViewController composeViewControllerForServiceType:service];
[controller setInitialText:text];
[controller addImage:image];
[controller addURL:[NSURL URLWithString:url]];
controller.completionHandler = ^(SLComposeViewControllerResult result) {
if( SLComposeViewControllerResultDone == result )
{
NSLog(#"rewards for share: %#!", service );
}
if( ![SLServiceTypeFacebook isEqualToString:service] ) // facebook behaves
[[CBLAppDelegate instance].activeViewController dismissViewControllerAnimated:true completion:nil];
};
[[CBLAppDelegate instance].activeViewController presentViewController:controller animated:true completion:nil];
}
Found the issue. It only happens when a completion handler is added to TWTweetComposeViewController. If added, make sure to call:
[self dismissModalViewControllerAnimated:YES];
Try this buddy
[mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
switch (result) {
case SLComposeViewControllerResultCancelled:
[self performSelector:#selector(showalert)];
[mySLComposerSheet dismissViewControllerAnimated:YES completion:nil];
break;
case SLComposeViewControllerResultDone:
[self performSelector:#selector(showalert1)];
[mySLComposerSheet dismissViewControllerAnimated:YES completion:nil];
break;
default:
break;
}
}];
Posting comment above as an answer:
Have you tried setting the completionHandler before presenting the View Controller?
Related
I have implemented Facebook sharing in my app. But When composerview is opened and i tapped on post, after that it will block my app. I am not able to navigate to other view controller. Here is the code that i have used:
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultCancelled) {
} else {
}
[controller dismissViewControllerAnimated:YES completion:Nil];
};
controller.completionHandler = myBlock;
[controller setInitialText:strMsg];
[vc presentViewController:controller animated:YES completion:Nil];
I faced the same issue and debugged as well. In my case it was not a hang; after the SLCompeseViewController disappeared (moved up the screen) there were some UIViews, UIControls remaining on the controller.view which hinder user interaction (i think it is the same in your app).
If it is the same case, you will never be able to remove those Views because the completion handler is never called.
This is a bug in iOS8, here is the link.
https://developers.facebook.com/bugs/962985360399542/?search_id
I suggest you to use UIActivityViewController instead of SLComposeViewController.
I create application with feature 'shared with facebook'
I use this code for make a facebook sharing
[facebookViewController setInitialText:[NSString stringWithFormat:#"via %#", self.randomGame.name]];
NSLog(#"%#", self.resultImageView.image);
[facebookViewController addImage:self.resultImageView.image];
[facebookViewController setCompletionHandler:^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultCancelled) {
NSLog(#"Dialog Did Cancel");
}
}];
[self presentViewController:facebookViewController animated:YES completion:nil];
I already have allocation/initialization facebookViewController object with SLComposeViewController.
first time I share there is no problem.
But, I share second time I get a shadow screen like this
can anyone help ?
Thanks for advance.
i am not sure but every time you present the facebook popover you also need to dismiss it in the completion block like
[facebookViewController dismissViewControllerAnimated:YES completion:Nil];
hope it helps
I done it with code
facebookViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[facebookViewController setInitialText:[NSString stringWithFormat:#"via %#", self.randomGame.name]];
[facebookViewController addImage:self.resultImageView.image];
[self presentViewController:facebookViewController animated:YES completion:nil];
- (IBAction)SendTxt:(id)sender {
MFMessageComposeViewController *textComposer = [[MFMessageComposeViewController alloc] init];
[textComposer setMessageComposeDelegate:self];
if ([MFMessageComposeViewController canSendText]) {
[textComposer setRecipients:[NSArray arrayWithObjects:#"123456",#"123456", nil]];
[textComposer setBody:#"HELP ME"];
[self presentViewController:textComposer animated:YES completion:NO];
}
else {
NSLog(#"Can't open Text");
}
}
-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
switch (result) {
case MessageComposeResultSent:
NSLog(#"SENT");
break;
case MessageComposeResultFailed:
NSLog(#"FAILED");
break;
case MessageComposeResultCancelled:
NSLog(#"CANCELLED");
break;
default:
break;
}
}
I have the above code which brings up the sms window as normal..
It works ok and sends a SMS but the SMS window will not close after sending or cancelling..
The NSLog registers the send or cancel but the SMS window will not go away!
Can anyone help?
Thanks
Mat
You have to dismiss it yourself using
[self dismissViewControllerAnimated:YES completion:^{ // something to do on completion if you need}];
I have implemented facebook and twitter for ios6, but I'm not getting user details like name, email, image. Would help me anybody for this? Below is my code:
-(IBAction)facebook
{
SLComposeViewController *fbController=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
SLComposeViewControllerCompletionHandler __block completionHandler=^(SLComposeViewControllerResult result){
[fbController dismissViewControllerAnimated:YES completion:nil];
switch(result){
case SLComposeViewControllerResultCancelled:
default:
{
NSLog(#"Cancelled.....facebook");
}
break;
case SLComposeViewControllerResultDone:
{
NSLog(#"Posted....facebook");
}
break;
}};
[fbController addImage:[UIImage imageNamed:#"ipadicon_72x72.png"]];
[fbController setInitialText:#"Check out this article."];
//[fbController addURL:[NSURL URLWithString:#"http://soulwithmobiletechnology.blogspot.com/"]];
[fbController setCompletionHandler:completionHandler];
[self presentViewController:fbController animated:YES completion:nil];
}
}
See this info on using the Twitter framework and how to get information from Twitter, specifically, see Step 7.
http://mobile.tutsplus.com/tutorials/iphone/ios-sdk_twitter-framework_twrequest/
I am posting to Facebook using the social api of iOS 6.
I am using the tradicional SLComposeViewController, like in..
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
...
at some point I do
[controller addImage:imageFacebook];
where imageFacebook is a screenshot that is 280 pixels high and then I post to Facebook.
My problem is this. I am following similar approach with the twitter API, but when that little window shows, there is a thumbnail of the image I am sending, hold by a clips on the right side, but on the facebook counterpart I see this safari-like icon. Is this normal? I would be a happy man if I was seen here a miniature of the image being posted, as I saw with the twitter API...
NOTE: the image is being posted correctly to Facebook... my problem is this icon on the posting window.
Is there a way to change that icon?
thanks
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultCancelled) {
NSLog(#"Cancelled");
} else {
NSLog(#"Done");
}
[controller dismissViewControllerAnimated:YES completion:Nil];
};
controller.completionHandler = myBlock;
[controller setInitialText:#"Enter Your Text Here:"];
[controller addURL:[NSURL URLWithString:#"http://www.google.com"]];
[controller addImage:[UIImage imageNamed:#"image001-794043.jpeg"]];
[self presentViewController:controller animated:YES completion:Nil];
} else {
NSLog(#"UnAvailable");
}