インターネットでいくつかの参考文献を読んだ後、Facebook SDK for iOS
代わりにを使用することにしXCode Social Framework
ました。
私のアプリで必要なのは「Facebookでログイン」セッションであり、Sampleフォルダーの下にあるSessionLoginSampleという名前のサンプルコードに従っていますが、コードを配置すると機能しません。これらのコードは iPad シミュレーターで正常にビルドされましたが、ボタンをクリックしても何も起こりません。
ここで見逃した場所を教えてください...ありがとう...
私はこのAppDelegate.hを持っています:
#import <UIKit/UIKit.h>
#import <FacebookSDK/FacebookSDK.h>
@class ViewController;
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) ViewController *viewController;
@property (strong, nonatomic) FBSession *session;
@end
ここに私の AppDelegate.mがあります:
#import "AppDelegate.h"
#import "ViewController.h"
@implementation AppDelegate
@synthesize window = _window;
@synthesize viewController = _viewController;
@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.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
[FBAppEvents activateApp];
[FBAppCall handleDidBecomeActiveWithSession:self.session];
}
- (void)applicationWillTerminate:(UIApplication *)application
{
[self.session close];
}
- (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];
}
#pragma mark Template generated code
@end
私のViewController.h:
#import <UIKit/UIKit.h>
#import <FacebookSDK/FacebookSDK.h>
@interface ViewController : UIViewController
@property (strong, nonatomic) IBOutlet UITextField *fieldEmail;
@property (strong, nonatomic) IBOutlet UITextField *fieldPassword;
@property (strong, nonatomic) IBOutlet UILabel *titleLogin;
@property (strong, nonatomic) IBOutlet UILabel *labelOutput;
- (IBAction)buttonRegister;
- (IBAction)buttonLogin;
- (IBAction)loginFacebook;
- (IBAction)loginTwitter;
@end
私のViewController.m:
#import "ViewController.h"
#import "AppDelegate.h"
@interface ViewController ()
@property (strong, nonatomic) UINavigationController* navController;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (void) alertWithTitle:(NSString *)title andMessage:(NSString *)msg
{
UIAlertView *message = [[UIAlertView alloc] initWithTitle:title
message:msg
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[message show];
}
- (IBAction)loginFacebook {
AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
if (appDelegate.session.isOpen) {
[appDelegate.session closeAndClearTokenInformation];
} else {
if (appDelegate.session.state != FBSessionStateCreated) {
appDelegate.session = [[FBSession alloc] init];
}
[appDelegate.session openWithCompletionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
[self alertWithTitle:(@"FB Login") andMessage:(@"It works!!")];
}];
} }
}
@end
更新: プロジェクトの Framework フォルダーの下に FacebookSDK.framework を追加し、この紹介に基づいて plist ファイルも変更しました: