gpt4 book ai didi

ios - Facebook sdk 集成打开移动站点登录屏幕而不是在 IOS 中询问权限

转载 作者:行者123 更新时间:2023-11-28 20:16:03 25 4
gpt4 key购买 nike

我在为 IOS 集成 Facebook SDK 时遇到了一个奇怪的问题,但它并没有出现在我所有的设备上。在我的 iPhone 上它工作正常,但在我的 ipad 上它给了我问题。我的应用程序中有一个“分享”按钮,在我的 iPhone 中,当我按下它时,我会看到一个请求许可的屏幕,然后发布就发生了。

在我的 iPad 上,它会打开一个屏幕,我应该在其中输入用户名和密码,但它不会从已登录的 Facebook 帐户中获取它们。

这是我的代码:

- (void)sharetoMyWall{
if (!FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded) {
NSLog(@" first time access");
[self openSession];
} else if (!FBSession.activeSession.isOpen) {
NSLog(@"active session is not open");
[self openSession];
}

if (FBSession.activeSession.isOpen) {
NSArray *permissions =
[NSArray arrayWithObjects:@"publish_stream", nil];

if ([[[FBSession activeSession]permissions]indexOfObject:@"publish_actions"] == NSNotFound) {
[[FBSession activeSession] requestNewPublishPermissions:permissions
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
//handle success + failure in block
[self postToMyWall];
}];
} else {
[self postToMyWall];
}
}

- (void)openSession
{



[FBSession openActiveSessionWithReadPermissions:nil
allowLoginUI:YES
completionHandler:
^(FBSession *session,
FBSessionState state, NSError *error) {
[self sessionStateChanged:session state:state error:error];
}];
}

我错过了什么?

还有一个问题:Facebook 应该从“设置”>“Facebook”以“我的名字”登录,还是只需要登录。因为这是我的 iPhone 和 iPad 之间的唯一区别。在我的 iPhone 中,我可以看到我从设置中登录,而在 iPad 中我从设置中注销(尽管我在 Facebook 应用程序本身中登录)

最佳答案

试试这段代码

- (IBAction)facebookShareBtn_TouchUpInside:(UIButton *)sender
{
//Ask for publish_actions permissions in context
if ([FBSession.activeSession.permissions
indexOfObject:@"publish_actions"] == NSNotFound) {
// Permission hasn't been granted, so ask for publish_actions
[FBSession openActiveSessionWithPublishPermissions:@[@"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
if (FBSession.activeSession.isOpen && !error) {
// Publish the story if permission was granted
[self publishStory];
}
}];
} else {
// If permissions present, publish the story
[self publishStory];
}
}


- (void)publishStory
{
NSMutableDictionary *params = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Me Something", @"name",@"Think of it as your personal.So what are you waiting for.....!", @"description", @"http://support24hour.com/workplace2/askie/ic_launcher.png", @"picture", nil];

[FBRequestConnection startWithGraphPath:@"me/feed" parameters:params 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 = [NSString stringWithFormat:
@"Posted action, id: %@",
result[@"id"]];
}
// Show the result in an alert
[[[UIAlertView alloc] initWithTitle:@"Result" message:alertText delegate:self cancelButtonTitle:@"OK!" otherButtonTitles:nil]show];
}];
}

关于ios - Facebook sdk 集成打开移动站点登录屏幕而不是在 IOS 中询问权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18079422/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com