如何不每次都要求发布权限?

时间:2013-08-26 10:06:41

标签: ios iphone objective-c facebook facebook-ios-sdk

我在Facebook上做了这个

[self vSuspendAndHaltThisThreadTillUnsuspendedWhileDoing:^{
    [[NSOperationQueue mainQueue] addOperationWithBlock:^{
        [self.ACAstore requestAccessToAccountsWithType:self.ACAccounts options:[self dicPostOptions] completion:^(BOOL granted, NSError *error) {
            self.bPermissionToAccessStoreGranted=granted;
            [self vContinue];
        }];
    }];
}];

基本上我要求获得发布许可。我想要做的是在再次询问之前检查是否已授予此类发布权限。

怎么做?

3 个答案:

答案 0 :(得分:0)

检查可用权限:

      if(![postRequest.session.permissions containsObject:@"publish_actions"])

答案 1 :(得分:0)

您可以使用FBRequest打开图形API制作me/permissions。它将返回一个带有字典的响应,其中键是权限。

FBRequest *req = [FBRequest requestWithGraphPath:@"me/permissions" parameters:Nil HTTPMethod:@"GET"];
[req startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary* result,
NSError *error) {
      BOOL canPublish = FALSE;
      if (!error)
      {
         FBGraphObject *data = [result objectForKey:@"data"];
         for(NSDictionary<FBGraphObject> *aKey in data) 
         {
             canPublish = [[aKey objectForKey:@"publish_stream"] boolValue];
         }
      }
      else
      {
         NSLog(@"%@", error);
      }

      NSLog(@"%@", canPublish ? @"I have publish perms" : @"I don't have publish perms");
}];

答案 2 :(得分:0)

试试这个 -

首先在你的app delegate中实现所有facebook sdk委托方法。

- (IBAction)loginWithFacebookButtonTapped:(id)sender
{
    IntubeAppDelegate *delegat = (IntubeAppDelegate*)[[UIApplication sharedApplication] delegate];
    [delegat doLoginAndSwitch];
}

现在,在你的appDelegate -

-(void) doLoginAndSwitch
{      
    [self openSessionWithAllowLoginUI:YES];
}

- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI
{
    NSArray *permissions = [NSArray arrayWithObjects:@"email", nil]; 
    return [FBSession openActiveSessionWithPublishPermissions:permissions
                                      defaultAudience:FBSessionDefaultAudienceFriends
                                         allowLoginUI:YES
                                    completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {

                                        [self sessionStateChanged:session
                                                            state:state
                                                            error:error];

                                    }];
}

-(BOOL)openSessionWithAllowPublishStreamPermission:(BOOL)allowLoginUI
{
    NSArray *permissions = [NSArray arrayWithObjects:@"publish_actions",@"publish_stream", nil];

[[FBSession activeSession] requestNewPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceEveryone completionHandler:^(FBSession *session, NSError *error){
}];
    return YES;
}

- (void)sessionStateChanged:(FBSession *)session
              state:(FBSessionState)state
              error:(NSError *)error
{
    switch (state) {
        case FBSessionStateOpen:
            if(!error)
            {
                //  NSLog(@"FBSessionStateOpen :- logged in");

                [self openSessionWithAllowPublishStreamPermission:YES];

               // Your code
            }
     }    
} 

我希望你能得到你现在想要的东西。 :)