Я создаю приложение с навигационной панелью в навигационной панели.Facebook ios sdk login from UINavigationBar
Я пытаюсь понять, как использовать facebook sdk для подключения к facebook (аутентификация) при нажатии кнопки.
Это не какой-то специальный диспетчер представлений или что-то в этом роде.
Я видел это: http://developers.facebook.com/docs/tutorials/ios-sdk-tutorial/authenticate/
но там мне нужно, чтобы создать некоторые вещи в делегатом (как UINavigationController), что я не могу использовать, потому что я использую UITabBarController ..
как я могу реализовать логин facebook и создание сеанса только от нажатия UINavigationItem?
Вот мой AppDelegate.h:
#import <UIKit/UIKit.h>
#import <FacebookSDK/FacebookSDK.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UITabBarController *tbc;
@property (strong, nonatomic) FBSession *session;
@end
И мой AppDelegate.m:
#import "AppDelegate.h"
#import "StatusView.h"
#import "JokesView.h"
#import "HomeView.h"
#import "TopTenView.h"
#import "UploadView.h"
@implementation AppDelegate
@synthesize tbc;
@synthesize window = _window;
@synthesize session = _session;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
UINavigationController*nav1 = [[UINavigationController alloc]init];
UINavigationController*nav2 = [[UINavigationController alloc]init];
UINavigationController*nav3 = [[UINavigationController alloc]init];
UINavigationController*nav4 = [[UINavigationController alloc]init];
UINavigationController*nav5 = [[UINavigationController alloc]init];
StatusView*page1 = [[StatusView alloc]initWithNibName:@"StatusView" bundle:nil];
JokesView*page2 = [[JokesView alloc]initWithNibName:@"JokesView" bundle:nil];
HomeView*page3 = [[HomeView alloc]initWithNibName:@"HomeView" bundle:nil];
TopTenView*page4 = [[TopTenView alloc]initWithNibName:@"TopTenView" bundle:nil];
UploadView*page5 = [[UploadView alloc]initWithNibName:@"UploadView" bundle:nil];
page1.title = @"סטטוסים";
page2.title = @"תמונות";
page3.title = @"ראשי";
page4.title = @"Top 10";
page5.title = @"העלאה";
UITabBarItem *tab1 = [[UITabBarItem alloc] initWithTitle:@"Status"
image:[UIImage imageNamed:@"tbc-status.png"] tag:1];
[nav1 setTabBarItem:tab1];
UITabBarItem *tab2 = [[UITabBarItem alloc] initWithTitle:@"Jokes"
image:[UIImage imageNamed:@"tbc-jokes.png"] tag:1];
[nav2 setTabBarItem:tab2];
UITabBarItem *tab3 = [[UITabBarItem alloc] initWithTitle:@"Home"
image:[UIImage imageNamed:@"tbc-home.png"] tag:1];
[nav3 setTabBarItem:tab3];
UITabBarItem *tab4 = [[UITabBarItem alloc] initWithTitle:@"Tpp10"
image:[UIImage imageNamed:@"tbc-topten.png"] tag:1];
[nav4 setTabBarItem:tab4];
UITabBarItem *tab5 = [[UITabBarItem alloc] initWithTitle:@"Upload"
image:[UIImage imageNamed:@"tbc-upload.png"] tag:1];
[nav5 setTabBarItem:tab5];
[nav1 pushViewController:page1 animated:NO];
[nav2 pushViewController:page2 animated:NO];
[nav3 pushViewController:page3 animated:NO];
[nav4 pushViewController:page4 animated:NO];
[nav5 pushViewController:page5 animated:NO];
tbc = [[UITabBarController alloc]init];
tbc.viewControllers = [NSArray arrayWithObjects:nav5,nav4,nav3,nav2,nav1, nil];
tbc.selectedIndex = 2;
// NavBar Design
UIImage *navbarPortrait = [[UIImage imageNamed:@"topbar.jpg"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
UIImage *navbarLandscape = [[UIImage imageNamed:@"topbar.jpg"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UINavigationBar appearance] setBackgroundImage:navbarPortrait
forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setBackgroundImage:navbarLandscape
forBarMetrics:UIBarMetricsLandscapePhone];
// NavBar Design End
// TabBar Design
UIImage *tabBackground = [[UIImage imageNamed:@"tbcb3ack.png"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UITabBar appearance] setBackgroundImage:tabBackground];
[[tbc tabBar] setBackgroundImage:tabBackground];
// TabBar Design End
[self.window addSubview:tbc.view];
self.window.rootViewController = self.tbc;
// Push Notifications
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeNone)];
// Push Notifications End
// Facebook Code Start
//UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Not Logged in"
// message:@"You Log in to use all the fearues in this app"
// delegate:nil
// cancelButtonTitle:@"OK"
// otherButtonTitles:nil];
if (FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded) {
// To-do, show logged in view
} else {
//[alert show];
}
// Facebook Code End
[self.window makeKeyAndVisible];
return YES;
}
// Facebook sdk code Start
- (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
withSession:self.session];
}
// Facebook sdk code End
- (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)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
[FBAppCall handleDidBecomeActiveWithSession:self.session];
}
#pragma mark Template generated code
@end
Это после того, как я использовал аутентификации учебник facebook Иос, до фактического фб изменения сеанса и кнопка входа в систему.
Что вы пробовали? Можете ли вы опубликовать код? – laxonline
Я пробовал только один и какой-то старый учебник ... У меня нет текущего кода, потому что он просто не работает, поскольку я пытаюсь не использовать логин в качестве полного контроллера представления, но как функцию anyviewcontroller у меня есть/ –