简体   繁体   English

阅读权限后直接要求发布权限-适用于iOS 6的Facebook SDK

[英]Ask for publish permissions directly after read permissions - Facebook SDK for iOS 6

The Facebook SDK for iOS 6 mandates that you ask for Read Permissions before Publish Permissions, and suggests strongly that you only ask for Publish Permissions in context. iOS 6的Facebook SDK要求您在发布权限之前要求读取权限,并强烈建议您仅在上下文中要求发布权限。 I, however, am not using FB login for login or anything related to read permissions, I just want people to be able to publish behavior in the app. 但是,我没有使用FB登录进行登录或与读取权限相关的任何操作,我只是希望人们能够在应用程序中发布行为。

I want to simply ask for read permissions and then immediately ask for publish permissions in the native permissions dialog. 我只想简单地要求读取权限,然后立即在本机权限对话框中要求发布权限。 The only way I've found to do it is by modifying the FBLoginView (which is the login view that comes packaged with the app), but I want to do it my own button that, if the user is logged in, posts to FB. 我发现这样做的唯一方法是修改FBLoginView(这是应用程序附带的登录视图),但是我想用我自己的按钮执行此操作,如果用户已登录,则将其发布到FB 。

This it the call I have now 这就是我现在的电话

[appDelegate openSessionWithAllowLoginUI:YES];

Which calls this in the delegate 在委托中将其称为

- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {
NSArray *permissions = [[NSArray alloc] initWithObjects:
                        @"email",
                        @"user_likes",
                        nil];
return [FBSession openActiveSessionWithReadPermissions:permissions
                                          allowLoginUI:allowLoginUI
                                     completionHandler:^(FBSession *session,
                                                         FBSessionState state,
                                                         NSError *error) {
                                         [self sessionStateChanged:session
                                                             state:state
                                                             error:error];
                                     }];

} }

How do I either modify that function OR immediately call an "openActiveSessionwithPublishPermissions" function after the read permissions are authorized? 如何修改该函数或在授予读取权限后立即调用“ openActiveSessionwithPublishPermissions”函数?

you could call openActiveSessionwithPublishPermissions in the openActiveSessionWithReadPermissions s completion Handler. 您可以在openActiveSessionWithReadPermissions的完成处理openActiveSessionwithPublishPermissions中调用openActiveSessionwithPublishPermissions Right after [self sessionStateChanged:session state:state error:error]; 就在[self sessionStateChanged:session state:state error:error];

Update: 更新:

For example. 例如。 I've accomplished this, the following way: 我是通过以下方式完成此操作的:

I created this method in a class that I use to manage all the facebook transactions: 我在用于管理所有Facebook交易的类中创建了此方法:

- (void)attemptToConnectToFacebookForFirstTime:(void (^)(bool granted))completion
{
    ACAccountType *facebookAccountType = [accountStore
                                          accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];

    // Specify App ID and permissions
    NSDictionary *options = @{
                              ACFacebookAppIdKey: @"000000000000",
                              ACFacebookPermissionsKey: @[@"email"],
                              ACFacebookAudienceKey: ACFacebookAudienceEveryone
                              };

    [accountStore requestAccessToAccountsWithType:facebookAccountType
                                          options:options 
                                       completion:^(BOOL granted, NSError *e)
     {
         // if you gotta do something here, then do it.
         // and then call the completion

         completion(granted);
     }];
}

then created this one: 然后创建这个:

- (void)connectToFacebook:(void (^)(bool granted))completion
{
    ACAccountType *facebookAccountType = [accountStore
                                          accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];

    // Specify App ID and permissions
    NSDictionary *options = @{
                              ACFacebookAppIdKey: @"0000000000000",
                              ACFacebookPermissionsKey: @[@"publish_stream",
                                                          @"publish_actions"],
                              ACFacebookAudienceKey: ACFacebookAudienceEveryone
                              };

    [accountStore requestAccessToAccountsWithType:facebookAccountType
                                          options:options 
                                       completion:^(BOOL granted, NSError *e)
     {
         // do what you gotta do, and call completion
         completion();
     }];
}

and then call them this way: 然后这样称呼他们:

[[FacebookManager sharedManager] attemptToConnectToFacebookForFirstTime:^(bool granted)
{
    if (granted)
    {
        [[FacebookManager sharedManager] connectToFacebook:^(bool granted)
        {
            // do something
        }
    }
}

My version is not using the facebook SDK, but the idea is the same. 我的版本未使用facebook SDK,但想法是相同的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM