iOS6社交框架未显示帐户警报

iOS6社交框架未显示帐户警报,ios,Ios,与类似,但我尝试使用SLRequest: 当用户未在设置中登录到Facebook时,我试图发出“无Facebook帐户”警报。我发现该警报出现在您显示SLComposeViewController之后,而不是在if语句中 if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) { SLComposeViewController *controller = [SLComposeViewCon

与类似,但我尝试使用SLRequest:

当用户未在设置中登录到Facebook时,我试图发出“无Facebook帐户”警报。我发现该警报出现在您显示SLComposeViewController之后,而不是在if语句中

if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
    SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

    //setup controller and callback code

    [self presentViewController:controller animated:YES completion:nil];
}
但是,我正在尝试使用SLRequest,我不想显示SLComposeViewController,而是在检查帐户后,弹出警报。我的代码在这里:

- (void)postImageFB
{
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
    NSLog(@"can post");
} else {
    NSLog(@"cant post");
}

ACAccountStore *accountStore = [[ACAccountStore alloc] init];

ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];

NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];
NSLog(@"accounts: %i", [accountsArray count]);

// Is it possible to popup the alert here if accounts = 0?

NSDictionary *options = @{ ACFacebookAppIdKey: @"123456789", ACFacebookPermissionsKey: @[@"publish_stream"], ACFacebookAudienceKey: ACFacebookAudienceFriends };

[accountStore requestAccessToAccountsWithType:accountType options:options completion:^(BOOL granted, NSError *error) {
    if(granted) {

        NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];

        if ([accountsArray count] > 0) {

            ACAccount *facebookAccount = [accountsArray objectAtIndex:0];

            NSDictionary *parameters = @{@"message": @"testing"};

            SLRequest *facebookRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
                                                            requestMethod:SLRequestMethodPOST
                                                                      URL:[NSURL URLWithString:@"https://graph.facebook.com/me/photos"]
                                                               parameters:parameters];

            [facebookRequest addMultipartData: [self getImageDataFromPlistWithFilename:@"image1.png"]
                                     withName:@"source"
                                         type:@"multipart/form-data"
                                     filename:@"TestImage"];

            facebookRequest.account = facebookAccount;

            [facebookRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
             {
                 if (error) {
                     NSLog(@"%@",error.description);
                 } else {
                     NSLog(@"responedata:%@", [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]);
                 }

             }];
        }
    }
}];

}

好吧,我发现了 于是开始在设备上进行测试

我认为使用不可见的SLComposeViewController来启动警报似乎是一个合适的解决方法:

if (![SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {

    SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
    controller.view.hidden = YES;
    [self presentViewController:controller animated:NO completion:nil];

} else {

    // Put posting code here: SLComposeViewController or SLRequest

}

然而,这在后台显示键盘,这是不合适的