14

I'm trying to implement the new social framework in iOS6, and have it working, except for 2 weird problems. If I've enabled the services I'm interested in (say... FaceBook), then it works fine. However, if the accounts are deleted from the settings panel (let's say FaceBook, to be consistent), then I get differing, and frustrating behaviors in the simulator and the device.

Here's the relevant code in my view controller:

//Method for FaceBook

- (IBAction)doFacebook:(id)sender{
//check to see if facebook account exists
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {

    // Create the view controller defined in the .h file

    fb=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

    // make the default string
    NSString *FBString= [NSString
                         stringWithFormat:@"%@\r via #GibberishGenerator", gibText.text];
    [fb setInitialText:FBString];
    // show the controller
    [self presentViewController:fb animated:YES completion:nil];

    }
}

And here's the weird behavior when firing off the above method:

In the simulator (version 6.0 (358.4) I get the dialog informing me that I haven't set up any faceBook accounts with "Settings" and "Cancel" buttons. Hitting "Settings" just dismisses the dialog, but doesn't take me to the settings panel.

On my iPhone 4s running 6.01, hitting the button that triggers the method results in... nothing. In other words, I get no dialog informing me that I have to set up a FaceBook account.

Thanks in advance for your help.


OK... Here's the fix:

Here's my new implementation, based on user1734802's helpful comment.

//Method for FaceBook

- (IBAction)doFacebook:(id)sender{

    // Create the view controller defined in the .h file

    fb=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

    // make the default string
    NSString *FBString= [NSString
                         stringWithFormat:@"%@\r via #GibberishGenerator", gibText.text];
    [fb setInitialText:FBString];
    // show the controller
    [self presentViewController:fb animated:YES completion:nil];

      }

At some point I expect

 [SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])

to actually work correctly (triggering the automatic dialog, and taking you to settings), so I actually just commented it out in my code.

james Burns
  • 864
  • 2
  • 9
  • 22
  • 1
    Smells like a bug to me. Doesn't work on device for any SLServiceType, and only works in the simulator for Twitter and Weibo. – Mick MacCallum Jan 05 '13 at 23:05
  • I'm beginning to believe it's a bug, as well. I wonder what's the best course of action? Pop up my own dialog advising folks to set up accounts (since I can't, apparently, send them to settings)? – james Burns Jan 06 '13 at 15:35
  • That's probably the best way to go, and other than that, if you end up not being able to get this working file a bug report with Apple at http://bugreporter.apple.com – Mick MacCallum Jan 06 '13 at 15:50

1 Answers1

28

I had the same problem, i fixed it by removing the If statement:

if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])

Then the view will display although there is no Facebook/Twitter account configured in the settings. And the "No Facebook/Twitter accounts" alertView showed! And I was able to hit the "Settings" button on the alert, and it directed me to the settings (Configure Facebook/Twitter account in the settings)

This is the code I used, and it works perfectly for me:

- (IBAction)bTwitter:(id)sender {

mySLComposerSheet = [[SLComposeViewController alloc] init];

mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];

[mySLComposerSheet setInitialText:@""];

[mySLComposerSheet addImage:[UIImage imageNamed:@""]];

[self presentViewController:mySLComposerSheet animated:YES completion:nil];

}
Peter
  • 1,848
  • 4
  • 26
  • 44
  • That sounds counterintuitive, but heck, I'll give it a try, and report back here to confirm. Thanks for the input. – james Burns Jan 10 '13 at 14:26
  • Yep. It worked for me, as well. Weird. I'll add this to my conclusions above. – james Burns Jan 10 '13 at 15:55
  • Does this work perfectly for you both on the simulator and a device, for both Twitter AND Facebook? On the simulator, the settings button doesn't seem to do anything for me when posting to Facebook without an account set up. Twitter works fine though, the settings button directs the user to the settings screen. – David Omid Jan 11 '13 at 18:21
  • It works for me, and obviously for him too! So I can't see the problem you are having. – Peter Jan 11 '13 at 18:39
  • So when you run this on the simulator without a Facebook account set up, and the alert dialog with the settings button pops up, you're able to click on the settings button and be directed to the Facebook settings page? On my simulator it doesn't do that, only does it for Twitter. Is the code you posted above the exact code you're using? – David Omid Jan 11 '13 at 18:49
  • It works perfect and exaclty the same for me on both facebook and twitter. – Peter Jan 12 '13 at 17:45
  • The only problem I have found is if you hit the home button, the no facebook account alert is persistent and I don't know how to dismiss it. – Will Larche May 20 '13 at 20:10
  • Hi guys it is not working in IOS 7.how can i fix this issue in IOS 7 – sabir Dec 02 '13 at 12:20
  • I don't understand why this is the case, does anyone know what happened to the isAvailableForServiceType: method? was it deprecated? – Jeremy Jan 28 '14 at 23:57