Facebook API 导致应用程序在切换回主视图时崩溃

发布于 2024-11-30 16:28:04 字数 3097 浏览 2 评论 0原文

注意:我对 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];

我一直在尝试自己调试它几个小时,但我自己并没有足够的知识来自己诊断它

。想法?

Heads Up: I'm not too comfortable with Objective C to know exactly what I'm talking about..

Here's my life story:
My app basically consists of 3 views: main, facebook, and twitter.. No problems with the twitter, no problems switching back and forth between views until... bum bum bum.. I started using the Facebook API in guidance from this site: http://www.mobisoftinfotech.com/blog/iphone/iphone-fbconnect-facebook-connect-tutorial/

Now I can connect to FB and use their API and post without any problem, but when I switch back from the Facebook View on my app to the main view, it switches and then immediately crashes..

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

I chopped some of the .m off of the post to save space, but you get the idea.. I've narrowed it down and it seems like the problem is caused during this line in .m

        appDelegate._session = [FBSession sessionForApplication:_APP_KEY secret:_SECRET_KEY delegate:self];

I've been trying to debug it myself for a few hours and I don't know enough on my own to diagnose it myself..

Any thoughts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

猫烠⑼条掵仅有一顆心 2024-12-07 16:28:04

我不确定你的应用程序崩溃的原因,但我想我会提到,有一些非常好的 Apple WWDC 视频,介绍 XCode 中的错误检查和崩溃。特别是“使用 Xcode 4 和 LLDB 进行调试”和“了解 iPhone OS 上的崩溃报告”,均来自 WWDC 2010 视频。我相信您需要开发人员登录才能访问这些视频,但如果您有兴趣了解有关调试的更多信息,那么绝对值得一看。

Im not sure why your app is crashing, but thought I'd mention that there are a few really good Apple WWDC videos about bug checking and crashing in XCode. In particular, "Debugging with Xcode 4 and LLDB" and "Understanding Crash Reports on iPhone OS", both from the WWDC 2010 videos. I believe you need a developer login to access these videos however but certainly worth a look if you're interested in learning more about debugging.

浪菊怪哟 2024-12-07 16:28:04

好吧,对于遇到此问题的其他人,这就是我所做的。

FacebookViewController.m 文件

- (void)dealloc {
[username release];
[usersession release];
[loginButton release];  
[super dealloc];
}

我注释掉了 [loginButton release];线而且它的工作方式很奇怪..我不知道这是否会给我带来严重的问题,但它现在有效..

Okay, for anyone else who had this issue, here's what I did..

FacebookViewController.m File

- (void)dealloc {
[username release];
[usersession release];
[loginButton release];  
[super dealloc];
}

I commented out the [loginButton release]; line and it worked oddly enough.. I don't know if this will give me serious problems down the road, but it works for now..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文