【问题标题】:how to direct the Facebook button to a certain view controller如何将 Facebook 按钮定向到某个视图控制器
【发布时间】:2016-03-28 01:45:55
【问题描述】:

我为我的应用程序创建了一个登录按钮,登录和注销功能适用于该应用程序。我目前遇到的问题是,一旦用户登录到应用程序,它只会显示一个注销按钮。我希望应用程序将 segue 引导到我的主视图控制器。 [一旦用户登录它显示此屏幕,我希望用户直接到主屏幕][1]

this is the main screen of the application, i would like the user to enter there login detail, once that has been a success i would like the user to be taken to this screen

登录屏幕和我的应用委托的以下代码

//
//  AppDelegate.m
//  SMAApplication
//
//  Created by MOHAMMED Shakeel on 23/03/2016.
//  Copyright © 2016 MOHAMMED Shakeel. All rights reserved.
//

#import "AppDelegate.h"
#import "AppDelegate.h"
#import "DetailViewController.h"
#import "Masterviewcontroller.h"
#import "data.h"
#import "FBSDKCoreKit/FBSDKCoreKit.h"
#import <FBSDKLoginKit/FBSDKLoginKit.h>




@interface AppDelegate ()

@end

@implementation AppDelegate


- (void)applicationDidBecomeActive:(UIApplication *)application {
    [FBSDKAppEvents activateApp];


}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [FBSDKProfile enableUpdatesOnAccessTokenChange:YES];
    [[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];



    // Override point for customization after application launch.


    [data getallNotes];
    return YES;
}
- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation {
    return [[FBSDKApplicationDelegate sharedInstance] application:application
                                                          openURL:url
                                                sourceApplication:sourceApplication
                                                       annotation:annotation];




}











- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}



- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    // Saves changes in the application's managed object context before the application terminates.
    [self saveContext];
}


#pragma mark - Core Data stack

@synthesize managedObjectContext = _managedObjectContext;
@synthesize managedObjectModel = _managedObjectModel;
@synthesize persistentStoreCoordinator = _persistentStoreCoordinator;

- (NSURL *)applicationDocumentsDirectory {
    // The directory the application uses to store the Core Data store file. This code uses a directory named "Shakeel.StudentManagementApplication" in the application's documents directory.
    return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
}

- (NSManagedObjectModel *)managedObjectModel {
    // The managed object model for the application. It is a fatal error for the application not to be able to find and load its model.
    if (_managedObjectModel != nil) {
        return _managedObjectModel;
    }
    NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"StudentManagementApplication" withExtension:@"momd"];
    _managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
    return _managedObjectModel;
}
#import "LoginViewController.h"
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import "FBSDKLoginKit/FBSDKLoginKit.h"


@interface LoginViewController ()



@end

@implementation LoginViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    FBSDKLoginButton *loginButton = [[FBSDKLoginButton alloc] init];
    loginButton.center = self.view.center;
    [self.view addSubview:loginButton];


}


#pragma mark - Navigation

 //In astoryboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {



    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}



- (IBAction)login:(id)sender {

    [self performSegueWithIdentifier:@"main" sender:self];
}
 @end

【问题讨论】:

    标签: objective-c iphone xcode facebook


    【解决方案1】:

    您可以使用FBSDKLoginButton - FBSDKLoginButtonDelegate 的委托方法。

    -(void)loginButton:(FBSDKLoginButton *)loginButton didCompleteWithResult:(FBSDKLoginManagerLoginResult *)结果错误:(NSError *)error

    {

    [self performSegueWithIdentifier:@"Segueid"sender:self];

    }

    此方法将在通过 Facebook 成功登录时调用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-25
      • 2013-05-01
      • 2011-07-21
      • 2012-05-05
      • 2014-05-05
      • 1970-01-01
      相关资源
      最近更新 更多