SLComposeViewController - "Attempting to submit" errors in iOS 8

Updating some code for iOS 8. I came across this error in the iPad application, which worked flawlessly in iOS 7. I use UIActionSheet to present options for sharing options, Facebook and Twitter give me a damn thing.

SLComposeViewController *facebookShare = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook]; //I add an image if there is one //I set some initial text [self presentViewController:facebookShare animated:YES completion:nil]; 

Pretty straight forward. But on iOS 8, I get lower

Warning: attempt to present SLComposeViewController: 0x1a238760> on PostDetailViewController: 0x180c5200>, which already represents (Zero)

I saw this error below, and I realized what it was all about. However, his statement by my PostDetailViewController already represents (null)?!? So basically it’s already occupied with nothing?

I tried to present the SLComposeViewController from another VC to the heart, but I keep getting Attempt to present error . I tried to submit from

UIViewController *vc = [UIApplication sharedApplication].keyWindow.rootViewController , and self.navigationController no avail. I also tried pushing the SLComposeViewController from self.navigationController, which actually works, but gives unwanted results as it pushes an empty background and stays there until the SLComposeViewController is closed and the user returns.

Any conclusions would be wonderful! Thanks in advance.

EDIT 1:

 -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{ if (buttonIndex == 0)[self shareWithTwitter]; if (buttonIndex == 1)[self shareWithFacebook]; if (buttonIndex == 2)[self shareWithiMessage]; if (buttonIndex == 3)[self shareWithEmail]; if (buttonIndex == 4)[self SaveImageToCameraRoll]; } -(void)shareWithFacebook{ if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) { //add animal URL SLComposeViewController *facebookShare = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook]; [facebookShare addURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.somelink.com/detail.aspx?id=%@",theAnimal.AnimalID]]]; //add image if there is one if (theAnimal.PhotoUrl) { [facebookShare addImage:imageView1.image]; } //set initial text if ([theAnimal.Sex isEqualToString:@"Male"]) { [facebookShare setInitialText:[NSString stringWithFormat:NSLocalizedString(@"pop_his_fb_share", nil),theAnimal.Name]]; }else [facebookShare setInitialText:[NSString stringWithFormat:NSLocalizedString(@"pop_her_fb_share", nil),theAnimal.Name]]; [self presentViewController:facebookShare animated:YES completion:nil]; } else { UIAlertView *alert = [[UIAlertView alloc]initWithTitle:[NSString stringWithFormat:NSLocalizedString(@"alert", nil)] message:[NSString stringWithFormat:NSLocalizedString(@"details_no_fb_account", nil)] delegate:nil cancelButtonTitle:[NSString stringWithFormat:NSLocalizedString(@"dismiss", nil)] otherButtonTitles:nil, nil]; [alert show]; } } 
+6
source share
2 answers

I found out that in iOS 8 the ActionSheet is actually considered a ViewController (at least I didn't know if this was before), so there was an error message. ActionSheet tries to reject when a button is clicked on the delegate method that I used:

 -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex 

This delegate gets me the button index on click, however the ActionSheet is still showing. When a click occurs, the representing ViewController tries to reject the ActionSheet, and I get my error.

I switched to:

 - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex 

(Note: didDismiss ). Therefore, my sharing methods are not called until the presentation ViewController rejects the ActionSheet, then it can share the ViewController!

Hope this helps someone else. Hooray!

+23
source

Just try the following.

 [[NSOperationQueue mainQueue] addOperationWithBlock:^{ [self presentViewController:fbViewController animated:YES completion:nil]; }]; 
0
source

Source: https://habr.com/ru/post/977167/


All Articles