Facebook 登录后更改视图控制器

2024-04-12

enter image description here I have my view controller listed below that handles the Facebook Login. As it is now, the app runs and loads a view that has the Facebook login button. Once logged in, the button changes the text to "Log out". What I would like to happen is once a user is logged in, it then goes to another view controller.

我在故事板中添加了一个新的视图控制器,并在两者之间进行了“segue”,但我觉得我错过了一些东西。如果有帮助的话,我制作的新视图控制器被命名为“homeViewController”。谢谢

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.loginView.readPermissions = @[@"public_profile", @"email", @"user_friends"];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView user:(id<FBGraphUser>)user
{
    NSLog(@"%@", user.name);
}

- (void)loginViewShowingLoggedInUser:(FBLoginView *)loginView
{
    NSLog(@"You are logged in! :) ");
}

- (void)loginViewShowingLoggedOutUser:(FBLoginView *)loginView
{
    NSLog(@"You are logged out! :( ");
}

- (void)loginView:(FBLoginView *)loginView handleError:(NSError *)error
{
    NSString *alertMessage, *alertTitle;

    if ([FBErrorUtility shouldNotifyUserForError:error])
    {
        alertTitle = @"Facebook error";
        alertMessage = [FBErrorUtility userMessageForError:error];

    }
    else if ([FBErrorUtility errorCategoryForError:error] == FBErrorCategoryAuthenticationReopenSession)
    {
        alertTitle = @"Session Error";
        alertMessage = @"Your current session is no longer valid. Please log in again.";

    }
    else if ([FBErrorUtility errorCategoryForError:error] == FBErrorCategoryUserCancelled)
    {
        NSLog(@"user cancelled login");

    }
    else
    {
        alertTitle  = @"Something went wrong";
        alertMessage = @"Please try again later.";
        NSLog(@"Unexpected error:%@", error);
    }

    if (alertMessage)
    {
        [[[UIAlertView alloc] initWithTitle:alertTitle
                                    message:alertMessage
                                   delegate:nil
                          cancelButtonTitle:@"OK"
                          otherButtonTitles:nil] show];
    }
}

@end

只要将 Segue 附加到 Facebook 登录按钮,它就应该是您所需要的。

如果你愿意的话可以打电话

- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender {
    if(currentUser ) { //this checks that the user logged in before moving to the next view
     return YES;
    }
    else return NO;
}

在移动到 homeViewController 之前检查用户是否成功登录。 你会做类似上面代码的事情

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Facebook 登录后更改视图控制器 的相关文章

  • 在 iOS 上使用 Web 服务的最佳方式?

    我想构建一个 iOS 应用程序 让您登录到网络服务 之后 应用程序将 当用户选择时 通过 https 发送登录名 密码以及请求的变量 例如 在请求 新闻更新 后 它将收到 XML 格式的请求信息 类似于
  • iPhone 应用程序在首次 Facebook Connect 授权/登录后崩溃

    我一直在到处寻找答案 但找不到 问题是 我有一个 iPhone 应用程序 在 AppStore 上 它使用脸书 iPhone SDK https github com facebook facebook iphone sdk 我使用 SDK
  • 如何更改 Facebook 应用程序的企业所有者? [关闭]

    Closed 这个问题是无关 help closed questions 目前不接受答案 是否可以更改 Facebook 应用程序的企业主 如果是 怎么办 是的 在应用程序仪表板中有一个名为 角色 的部分 在那里您可以添加一个新用户作为管理
  • 自定义 UITableViewCell 选择样式?

    当我点击我的UITableViewCell 当我单击单元格时 背景部分 我的背景图像未覆盖的区域 会变成蓝色 另外 所有的UILabel单击时单元格上的 s 变为白色 这就是我想要的 然而 我不想要的是当我点击它时的蓝色背景 但如果我这样做
  • 创建 Facebook 测试用户时访问令牌出现问题

    我正在尝试为我的 Facebook 应用程序创建测试用户 他们在 11 月份的博客文章 http developers facebook com blog post 429 中宣布了此功能 并在此处记录了该功能 http developer
  • 错误域=AVFoundationErrorDomain代码=-11814“无法记录”

    它不断给我错误 错误域 AVFoundationErrorDomain代码 11814 无法记录 我不确定问题是什么 我试图在拍照后计数器达到 1 时录制声音 static int counter counter will always b
  • 如何在 iOS 中更改部分透明图像的颜色?

    我有一个具有部分透明度的单色图像 我有正常版本和 2X 版本的图像 我希望能够用代码将图像着色为不同的颜色 下面的代码适用于普通图像 但 2X 最终会出现伪影 正常图像可能有类似的问题如果是这样 由于分辨率的原因我无法检测到它 UIImag
  • 推入 UINavigationController 时隐藏 FBFriendPickerViewController 导航栏

    介绍一个实例FBFriendPickerViewController using presentViewController animated completion 非常简单 该类似乎是针对该用例的 但是 我想推送一个实例FBFriendP
  • 使用 Interface Builder 创建 UIScrollView 的步骤

    我正在尝试使用 UIScrollView 但似乎有一些基本的事情我不理解 假设我想在我的 iPhone 应用程序中使用 UIScrollView 我有一个充满按钮的视图 尺寸为 320x700 显然 这对于 320x480 的 iPhone
  • iOS 中的 CSV 逐行解析

    我正在 Objective c 中解析 CSV 文件 该文件包含如下内容 line 40 Rising searches line 41 nabi avc Breakout line 42 stonewall 700 line 43 med
  • iOS 中的构建对象文件扩展名是什么?

    当我在项目中构建java对象类时 将创建带有 class扩展名的构建文件 并且人类不可读 快速构建文件怎么样 example car java gt build gt car class 构建后会是什么 car swift gt build
  • 以编程方式触发iOS摇动事件

    如何以编程方式触发 iOS 中的摇动事件 我尝试过以下方法 但它总是崩溃 void shake NSLog TEST UIMotionEventProxy m NSClassFromString UIMotionEvent alloc in
  • SiriKit 错误:此应用程序不支持捐赠意图

    我在 Xcode 10 iOS 12 Beta 中捐赠自定义意图时遇到问题 我创建了一个在我的主应用程序目标和 OrderIntent 目标之间共享的自定义框架 我创建了一个 intentdefinition 文件 并将目标成员资格设置为我
  • 我怎样才能勾勒出文本字体?

    我想在边框 轮廓 中显示另一种颜色的文本 我正在尝试使用在 MapOverlayView 中显示文本 text drawAtPoint CGPointMake 0 30 withFont UIFont fontWithName Helvet
  • UICollectionView 拖放文件夹创建

    我正在使用 UICollectionView 创建 iOS 画廊应用程序 我希望用户能够拖放图像来重新排序图库并创建文件夹 类似于 iPhone 上的主屏幕 我发现了以下内容tutorial http nshint io blog 2015
  • 防止 AlertView 被解雇

    任何人都可以帮助我防止在其按钮单击事件上解雇警报视图吗 我有一个 textview 作为我的alertView 的子视图 如果 textview 值为 nil 我不想关闭它 因为这是一个非常老的问题 但我得到了一个解决方案 并且如果其他开发
  • 在 UIImage 顶部绘制透明圆圈 - iPhone SDK

    我在尝试找出如何在 UIImageView 中的 UIImage 顶部绘制透明圆圈时遇到了很多麻烦 谷歌给了我线索 但我仍然找不到有效的例子 有没有人知道的例子可以证明这一点 最简单的方法就是创建一个半透明的方形 UIView 然后将其图层
  • WhatsApp 显示警告“此项目无法共享。请选择其他项目。”对于 iOS 应用程序。

    我正在开发一个 iOS 应用程序 在该应用程序中 我有社交共享功能 并且社交共享功能使用深度链接来共享 URL 该网址共享对于所有应用程序都运行良好 除了WhatsApp 它会显示一个警报弹出窗口 此项目无法共享 请选择其他项目 以下是我的
  • 拖动时获取MKAnnotation的坐标

    我正在根据用户添加的注释的位置创建一条路径 MKPolyline 我想允许用户通过拖动引脚来更改路径 我目前可以做到这一点 但 MKPolyline 不会更新 直到引脚被放下 我实施了 void mapView MKMapView mapV
  • 如何反转 CGPath 的点顺序

    我想画一个圆圈 并用它打出字母 为此 我需要顺时针抚摸圆圈 逆时针抚摸字母 这一切都很好 但是当我使用 Core Text 获取字母路径时 我不知道如何从本质上反转该路径 不是镜像或旋转或任何东西 这很简单 我希望点笔画顺序是逆时针的 这实

随机推荐