iOS 6 Social framework not going to settings or no alert

孤者浪人 提交于 2019-12-21 07:12:02

问题


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.


回答1:


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

}


来源:https://stackoverflow.com/questions/14145322/ios-6-social-framework-not-going-to-settings-or-no-alert

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!