简体   繁体   English

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

[英]Facebook API causes app to crash when switching back to main view

Heads Up: I'm not too comfortable with Objective C to know exactly what I'm talking about.. 注意:我对Objective C不太满意,无法确切地知道我在说什么。

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/ 这是我的生活故事:我的应用程序基本上包含3个视图:main,facebook和twitter。.twitter没问题,在视图之间来回切换没有问题,直到... bum bum bum ..我开始使用Facebook API在本网站的指导中: 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.. 现在,我可以连接到FB并使用其API并发布,没有任何问题,但是当我从应用程序上的Facebook View切换回主视图时,它切换并立即崩溃。

FacebookViewController.m 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 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 我从帖子中删掉了一些.m以节省空间,但您明白了。.我缩小了范围,似乎问题出在.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? 有什么想法吗?

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. 我不确定为什么您的应用会崩溃,但我想提到的是,关于XCode中的错误检查和崩溃,有一些非常不错的Apple WWDC视频。 In particular, " Debugging with Xcode 4 and LLDB " and " Understanding Crash Reports on iPhone OS ", both from the WWDC 2010 videos . 尤其是来自WWDC 2010视频的使用Xcode 4和LLDB进行调试 ”和“ 了解iPhone OS上的崩溃报告 ”。 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. 我相信您需要开发者登录才能访问这些视频,但是,如果您有兴趣了解有关调试的更多信息,那么一定值得一看。

Okay, for anyone else who had this issue, here's what I did.. 好吧,对于其他遇到此问题的人,这就是我所做的。

FacebookViewController.m File FacebookViewController.m文件

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

I commented out the [loginButton release]; 我注释掉了[loginButton版本]; 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.. 线,而且效果很好。.我不知道这是否会给我带来严重的问题,但目前仍然有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM