在Xcode下成功登录iOS应用程序后,如何将用户重定向到新的视图控制器
我对这个很陌生。我制作了一个iOS应用程序,并使用api密钥和密码在其中进行了fb集成。在我的应用程序中,我有3个视图控制器。在我的第一个视图控制器中,我有登录按钮,在第二个视图控制器中,我有我的应用程序首页,在第三个控制器中,我有我的应用程序信息页。我想要的是按下登录按钮并在成功验证后,控件应该返回到我的第二个视图控制器,而不是返回到具有登录按钮的第一个视图控制器。下面是我的代码: appdelegate.m #导入“AppDelegate.h” #进口 #导入“ViewController.h”在Xcode下成功登录iOS应用程序后,如何将用户重定向到新的视图控制器,ios,objective-c,xcode,facebook,Ios,Objective C,Xcode,Facebook,我对这个很陌生。我制作了一个iOS应用程序,并使用api密钥和密码在其中进行了fb集成。在我的应用程序中,我有3个视图控制器。在我的第一个视图控制器中,我有登录按钮,在第二个视图控制器中,我有我的应用程序首页,在第三个控制器中,我有我的应用程序信息页。我想要的是按下登录按钮并在成功验证后,控件应该返回到我的第二个视图控制器,而不是返回到具有登录按钮的第一个视图控制器。下面是我的代码: appdelegate.m #导入“AppDelegate.h” #进口 #导入“ViewController.
@实现AppDelegate
-(BOOL)应用程序:(UIApplication*)应用程序使用选项完成启动:(NSDictionary*)启动选项
{
[FBLoginView类];
//应用程序启动后自定义的覆盖点。
睡眠(2);
返回YES;
}
-(BOOL)应用程序:(UIApplication*)应用程序
openURL:(NSURL*)url
sourceApplication:(NSString*)sourceApplication
注释:(id)注释{
//尝试从url提取令牌
返回[FBAppCall handleOpenURL:url sourceApplication:sourceApplication];
}
-(无效)应用IDBECOMEACTIVE:(UIApplication*)应用{
//记录“安装”和“应用程序激活”应用程序事件。
[FBAppEvents activateApp];
}
@结束
**viewcontroller.m(我的第一个viewcontroller)**
#导入“ViewController.h”
#进口
#导入“AppDelegate.h”
@界面视图控制器()
@结束
@实现视图控制器
-(id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
self=[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
如果(自我){
//自定义初始化
}
回归自我;
}
-(无效)viewDidLoad
{
[超级视图下载];
//加载视图后执行任何其他设置。
//FBLoginView*loginView=[[FBLoginView alloc]init];
//[loginView设置框架:CGRectMake(553432150)];
//loginView.center=self.view.center;
//[self.view addSubview:loginView];
如果(![FBSession.activeSession isOpen])
{
//presentLoginViewController
返回;
}
其他的
{
[[FBRequest requestForMe]startWithCompletionHandler:
^(FBRequestConnection*连接,NSDictionary*用户,NSError*错误){
如果(!错误){
//self.label.text=user.name;
//self.userProfileImage.profileID=[user objectForKey:@“id]”;
//NSLog(@“FB id:%@”,appContext.userName);
//登录后显示视图控制器
//[self-PerformsgueWithIdentifier:@“身份验证”发送方:self];
UIViewController*ViewController=[[UIViewController alloc]initWithNibName:@“bundle:nil];
[自我呈现ModalviewController:ViewController动画:是];
//[视图控制器释放];
}
}];
}
}
//-(无效)loginView显示日志用户:(FBLoginView*)loginView
//{
//[self-PerformsgueWithIdentifier:@“身份验证”发送方:self];
//}
-(void)prepareForSegue:(UIStoryboardSegue*)segue发送方:(id)发送方{
//ViewController*transferViewController=segue.destinationViewController;
NSLog(@“prepareforsgue:%@”,序列标识符);
}
-(无效)未收到记忆警告
{
[超级记忆警告];
//处置所有可以重新创建的资源。
}
@结束
RU在Storyboard中使用xib您可以在登录验证后调用第二个视图控制器
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[FBLoginView class];
// Override point for customization after application launch.
sleep(2);
return YES;
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
// attempt to extract a token from the url
return [FBAppCall handleOpenURL:url sourceApplication:sourceApplication];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
// Logs 'install' and 'app activate' App Events.
[FBAppEvents activateApp];
}
@end
**viewcontroller.m(my firstviewcontroller)**
#import "ViewController.h"
#import <FacebookSDK/FacebookSDK.h>
#import "AppDelegate.h"
@interface ViewController ()
@end
@implementation ViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
//FBLoginView *loginView = [[FBLoginView alloc] init];
//[loginView setFrame:CGRectMake(55, 343, 210, 50)];
// loginView.center = self.view.center;
//[self.view addSubview:loginView];
if (![FBSession.activeSession isOpen])
{
// presentLoginViewController
return;
}
else
{
[[FBRequest requestForMe] startWithCompletionHandler:
^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
if (!error) {
//self.label.text = user.name;
//self.userProfileImage.profileID = [user objectForKey:@"id"];
// NSLog(@"FB id : %@",appContext.userName);
//Present your view controller after logged in
// [self performSegueWithIdentifier:@"authentication" sender:self];
UIViewController *ViewController = [[UIViewController alloc] initWithNibName:@"<name of xib>" bundle:nil];
[self presentModalViewController:ViewController animated:YES];
//[ViewController release];
}
}];
}
}
//- (void)loginViewShowingLoggedInUser:(FBLoginView *)loginView
//{
// [self performSegueWithIdentifier:@"authentication" sender:self];
//}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
// ViewController *transferViewController = segue.destinationViewController;
NSLog(@"prepareForSegue: %@", segue.identifier);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end