我目前正在尝试使用 iOS Facebook SDK 3.1 实现 Facebook-Login-Flow。但它有一个小问题。每次用户使用 facebook 登录时,webview 都会打开并显示
“你已经授权了 YOUR_APP..”
我基于以下示例编写的代码:单击此处 现在我的问题是,如何避免这种行为以及我做错了什么?
我目前正在尝试使用 iOS Facebook SDK 3.1 实现 Facebook-Login-Flow。但它有一个小问题。每次用户使用 facebook 登录时,webview 都会打开并显示
“你已经授权了 YOUR_APP..”
我基于以下示例编写的代码:单击此处 现在我的问题是,如何避免这种行为以及我做错了什么?
请查看此代码,它可能会有所帮助
postParams=
[@{
@"link" :link,
@"picture" :picture link , //[NSString stringWithFormat:@"%@%@",KBaseImageUrl,@"/assets/img/logo-small.jpg"],
@"name" : @“name”,
@"caption" : caption title,
@"description" :discription
} mutableCopy];
title=[[arrayEventInfo valueForKey:@"info"] valueForKey:@"eventname"];
if ([[FBSession activeSession]isOpen])
{
if ([[[FBSession activeSession]permissions]indexOfObject:@"publish_actions"] == NSNotFound)
{
[[FBSession activeSession] requestNewPublishPermissions:[NSArray arrayWithObject:@"publish_action"] defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session,NSError *error){
// If permissions granted, publish the story
[FBRequestConnection
startWithGraphPath:@"me/feed"
parameters:postParams
HTTPMethod:@"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
{
NSString *alertText;
if (error)
{
alertText = [NSString stringWithFormat:
@"error: domain = %@, code = %d",
error.domain, error.code];
}
else
{
alertText = @"Posted successfully on your wall.";//[NSString stringWithFormat:
//@"Posted action, id: %@",
// result[@"id"]];
}
//Show the result in an alert
[[[UIAlertView alloc] initWithTitle:title
message:alertText
delegate:self
cancelButtonTitle:@"OK" otherButtonTitles:nil]show];
[FBSession.activeSession closeAndClearTokenInformation];
[FBSession.activeSession close];
}];
UIActivityIndicatorView *activityView=(UIActivityIndicatorView*)[self.view viewWithTag:111];
if(activityView)
{
[activityView removeFromSuperview];
}
[self.view setUserInteractionEnabled:YES];
[self.navigationController.navigationBar setUserInteractionEnabled:YES];
}];
}else
{
// If permissions granted, publish the story
[FBRequestConnection
startWithGraphPath:@"me/feed"
parameters:postParams
HTTPMethod:@"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
{
NSString *alertText;
if (error)
{
alertText = [NSString stringWithFormat:
@"error: domain = %@, code = %d",
error.domain, error.code];
}
else
{
alertText = @"Posted successfully on your wall.";//[NSString stringWithFormat:
//@"Posted action, id: %@",
// result[@"id"]];
}
//Show the result in an alert
[[[UIAlertView alloc] initWithTitle:title
message:alertText
delegate:self
cancelButtonTitle:@"OK" otherButtonTitles:nil]show];
[FBSession.activeSession closeAndClearTokenInformation];
[FBSession.activeSession close];
}];
}
}
else
{
[FBSession openActiveSessionWithPublishPermissions:[NSArray arrayWithObject:@"publish_actions"]
defaultAudience:FBSessionDefaultAudienceOnlyMe
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
if (!error && status == FBSessionStateOpen) {
if (!error)
{
// If permissions granted, publish the story
[FBRequestConnection
startWithGraphPath:@"me/feed"
parameters:postParams
HTTPMethod:@"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
{
NSString *alertText;
if (error)
{
alertText = [NSString stringWithFormat:
@"error: domain = %@, code = %d",
error.domain, error.code];
}
else
{
alertText = @"Posted successfully on your wall.";//[NSString stringWithFormat:
//@"Posted action, id: %@",
// result[@"id"]];
}
//Show the result in an alert
[[[UIAlertView alloc] initWithTitle:title
message:alertText
delegate:self
cancelButtonTitle:@"OK" otherButtonTitles:nil]show];
[FBSession.activeSession closeAndClearTokenInformation];
[FBSession.activeSession close];
}];
}
}else{
NSLog(@"%@",[error description]);
UIActivityIndicatorView *activityView=(UIActivityIndicatorView*)[self.view viewWithTag:111];
if(activityView)
{
[activityView removeFromSuperview];
}
[self.view setUserInteractionEnabled:YES];
[self.navigationController.navigationBar setUserInteractionEnabled:YES];
}
}];
}
如果您在 dev 中测试代码,那么您第一次登录时,它将将该会话存储在 Facebook 上。
因此,您尝试再次对其进行测试,但它已被授权。
如果您想再次测试登录过程,请转到 Facebook 并取消授权您的应用程序(它将在您的应用程序列表中)。
然后您可以在设备上再次登录。