注意:我对 Objective C 不太满意,无法确切知道我在说什么......
这是我的人生故事:我的应用程序基本上由 3 个视图组成:主视图、facebook 和 twitter.. twitter 没有问题,在视图之间来回切换没有问题,直到...... bum bum bum.. 我开始使用 Facebook API在本网站的指导下:http ://www.mobisoftinfotech.com/blog/iphone/iphone-fbconnect-facebook-connect-tutorial/
现在我可以连接到 FB 并使用他们的 API 并毫无问题地发布,但是当我从我的应用程序上的 Facebook 视图切换回主视图时,它会切换然后立即崩溃..
FacebookViewController.m
#import "FacebookViewController.h"
#import "Crush_LoveAppDelegate.h"
#define _APP_KEY @"43e37a535cc09c2013bd76fde78dfcc7"
#define _SECRET_KEY @"cc14801521a0c4d1dc31b7cacb891072"
@implementation FacebookViewController
@synthesize facebookFeed;
@synthesize delegate;
@synthesize loginButton;
@synthesize facebookAlert;
@synthesize usersession;
@synthesize username;
@synthesize post;
- (void)viewDidLoad {
Crush_LoveAppDelegate *appDelegate =
(Crush_LoveAppDelegate *) [[UIApplication
sharedApplication]delegate];
if (appDelegate._session == nil){
appDelegate._session = [FBSession sessionForApplication:_APP_KEY secret:_SECRET_KEY delegate:self];
}
if(self.loginButton == NULL)
self.loginButton = [[[FBLoginButton alloc] init] autorelease];
loginButton.frame = CGRectMake(110, 200, 100, 50);
[self.view addSubview:loginButton];
[super viewDidLoad];
self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];
}
- (IBAction)done:(id)sender {
[self.delegate facebookViewControllerDidFinish:self];
}
FacebookViewController.h
#import <UIKit/UIKit.h>
#import "FBConnect/FBConnect.h"
#import "FBConnect/FBSession.h"
#import "FBConnect/FBRequest.h"
#import "FBConnect/FBStreamDialog.h"
@protocol FacebookViewControllerDelegate;
@interface FacebookViewController : UIViewController <UIApplicationDelegate, FBSessionDelegate, FBRequestDelegate>{
IBOutlet UIWebView *facebookFeed;
id <FacebookViewControllerDelegate> delegate;
FBLoginButton *loginButton;
UIAlertView *facebookAlert;
FBSession *usersession;
NSString *username;
BOOL post;
}
@property(nonatomic,retain) FBLoginButton *loginButton;
@property(nonatomic,retain) UIAlertView *facebookAlert;
@property(nonatomic,retain) FBSession *usersession;
@property(nonatomic,retain) NSString *username;
@property(nonatomic,assign) BOOL post;
@property (nonatomic, assign) id <FacebookViewControllerDelegate> delegate;
@property (nonatomic, retain) IBOutlet UIWebView *facebookFeed;
- (IBAction)done:(id)sender;
@end
@protocol FacebookViewControllerDelegate
- (void)facebookViewControllerDidFinish:(FacebookViewController *)controller;
- (BOOL)textFieldShouldReturn:(UITextField *)textField;
-(void)getFacebookName;
-(void)postToWall;
@end
我从帖子上切掉了一些 .m 以节省空间,但你明白了。我已经缩小了范围,似乎问题是在 .m 中的这一行引起的
appDelegate._session = [FBSession sessionForApplication:_APP_KEY secret:_SECRET_KEY delegate:self];
我已经尝试自己调试了几个小时,但我自己的了解还不够,无法自己诊断..
有什么想法吗?