如何不每次都请求发布许可?
Posted
技术标签:
【中文标题】如何不每次都请求发布许可?【英文标题】:How not to ask for publish permission everytime? 【发布时间】:2013-08-26 10:06:41 【问题描述】:我是在脸书上做的
[self vSuspendAndHaltThisThreadTillUnsuspendedWhileDoing:^
[[NSOperationQueue mainQueue] addOperationWithBlock:^
[self.ACAstore requestAccessToAccountsWithType:self.ACAccounts options:[self dicPostOptions] completion:^(BOOL granted, NSError *error)
self.bPermissionToAccessStoreGranted=granted;
[self vContinue];
];
];
];
基本上我要求发布许可。我要做的是在再次询问之前检查是否已授予此类发布权限。
怎么做?
【问题讨论】:
【参考方案1】:检查可用权限:
if(![postRequest.session.permissions containsObject:@"publish_actions"])
【讨论】:
什么是postRequest?从这里开始新程序。我正在使用社交框架。不是 facebook sdk。【参考方案2】:您可以使用带有me/permissions
的开放图形API 创建FBRequest
。它会返回一个带有字典的响应,其中键是权限。
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");
];
【讨论】:
但我使用的是社交框架。如果我使用社交框架,我需要做什么。【参考方案3】:试试这个 -
首先在您的应用委托中实现所有 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
我希望你现在能得到你想要的。 :)
【讨论】:
以上是关于如何不每次都请求发布许可?的主要内容,如果未能解决你的问题,请参考以下文章
requestLocation() 不请求许可,即使“下次询问”被勾选