首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iOS6社交框架显示无帐户警报

iOS6社交框架显示无帐户警报
EN

Stack Overflow用户
提问于 2013-04-18 10:47:11
回答 1查看 1.3K关注 0票数 0

类似于iOS 6 Social framework not going to settings or no alert,但我尝试使用SLRequest:

当用户尚未在设置中登录到Facebook时,我尝试调出警报"No Facebook Account“。我发现警报出现在您提供SLComposeViewController之后,而不是在if语句中。

代码语言:javascript
复制
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
    SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

    //setup controller and callback code

    [self presentViewController:controller animated:YES completion:nil];
}

但是,我正在尝试使用SLRequest,并且我不想显示SLComposeViewController,而是在检查帐户后弹出警报。我的代码如下:

代码语言:javascript
复制
- (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]);
                 }

             }];
        }
    }
}];

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-04-18 11:26:17

好的,我发现isAvailableForServiceType always returns true?已经开始在这个设备上测试了。

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

代码语言:javascript
复制
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

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16073667

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档