Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

newtoiphonesdk

macrumors 6502a
Original poster
Jul 30, 2010
567
2
I have 2 similar apps. On both there is one view controller with IBACtion for fb, and one view controller with UIActionSheet to access fb. On the BellAvenue2 file, it works fine: on both. BellAvenue2 has the initWithSession:_session code in the logindialog and has no problems posting to the wall.
LaGrange on the other hand also has initWithSession:_session code and it crashes every time. Could someone take a look at these and see what the difference is? I've been going through stuff for hours and have no clue. Again BellAvenue2 runs the code fine. LaGrange crashes and I have no clue why. I would greatly appreciate a 2nd pair of eyes.

Bell Avenue 2

La Grange

This is just weird. I have an app that uses an IBAction to login and post to facebook wall. I was having problems where it would crash on me after loggin in on one view, but the other view would log in just fine. I thought maybe I made a typo somewhere so I completely copied and pasted the code from the working view into the one that wasn't working. They are completely identical, except for me changing the import header file names and the implementation names to be for the correct view. It STILL messed up. Exactly the same code in 2 views, one works one doesn't. How can this be?
Code:
#import "FirstViewController.h"
#import <QuartzCore/QuartzCore.h>

@implementation FirstViewController
@synthesize activity;
@synthesize postentry;
@synthesize currentURL;
@synthesize title;
@synthesize session = _session;
@synthesize postGradesButton = _postGradesButton;
@synthesize logoutButton = _logoutButton;
@synthesize loginDialog = _loginDialog;
@synthesize facebookName = _facebookName;
@synthesize posting = _posting;
@synthesize text;


- (void)viewDidLoad {
	[steve loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://resurrectedliving.wordpress.com"]]];
	timer = [NSTimer scheduledTimerWithTimeInterval:(1.0/2.0) target:self selector:@selector(tick) userInfo:nil repeats:YES];
	
	// Set these values from your application page on http://www.facebook.com/developers
	// Keep in mind that this method is not as secure as using the sessionForApplication:getSessionProxy:delegate method!
	// These values are from a dummy facebook app I made called MyGrades - feel free to play around!
	static NSString* kApiKey = @"REMOVED ON PURPOSE";
	static NSString* kApiSecret = @"REMOVED ON PURPOSE";
	_session = [[FBSession sessionForApplication:kApiKey secret:kApiSecret delegate:self] retain];
	
	// Load a previous session from disk if available.  Note this will call session:didLogin if a valid session exists.
	[_session resume];
	
	[super viewDidLoad];
}
-(void)tick {
	if(!steve.loading)
		[activity stopAnimating];
	else 
		[activity startAnimating];
	
}

- (IBAction)postGradesTapped:(id)sender {
	_posting = YES;
	// If we're not logged in, log in first...
	if (![_session isConnected]) {
		self.loginDialog = nil;
		_loginDialog = [[FBLoginDialog alloc] initWithSession:_session];	
		[_loginDialog show];	
	}
	// If we have a session and a name, post to the wall!
	else if (_facebookName != nil) {
		[self postToWall];
	}
	// Otherwise, we don't have a name yet, just wait for that to come through.
}

- (IBAction)logoutButtonTapped:(id)sender {
	[_session logout];
}


#pragma mark FBSessionDelegate methods

- (void)session:(FBSession*)session didLogin:(FBUID)uid {
	[self getFacebookName];
}

- (void)session:(FBSession*)session willLogout:(FBUID)uid {
	_logoutButton.hidden = YES;
	_facebookName = nil;
}

#pragma mark Get Facebook Name Helper

- (void)getFacebookName {
	NSString* fql = [NSString stringWithFormat:
					 @"select uid,name from user where uid == %lld", _session.uid];
	NSDictionary* params = [NSDictionary dictionaryWithObject:fql forKey:@"query"];
	[[FBRequest requestWithDelegate:self] call:@"facebook.fql.query" params:params];
}

#pragma mark FBRequestDelegate methods

- (void)request:(FBRequest*)request didLoad:(id)result {
	if ([request.method isEqualToString:@"facebook.fql.query"]) {
		NSArray* users = result;
		NSDictionary* user = [users objectAtIndex:0];
		NSString* name = [user objectForKey:@"name"];
		self.facebookName = name;		
		_logoutButton.hidden = NO;
		[_logoutButton setTitle:[NSString stringWithFormat:@"Facebook: Logout as %@", name] forState:UIControlStateNormal];
		if (_posting) {
			[self postToWall];
			_posting = NO;
		}
	}
}

#pragma mark Post to Wall Helper

- (void)postToWall {
	
	FBStreamDialog* dialog = [[[FBStreamDialog alloc] init] autorelease];
	dialog.userMessagePrompt = @"Enter your message:";
	dialog.attachment = [NSString stringWithFormat:@"{\"name\":\"%@\",\"href\":\"%@\",\"caption\":\"Check out this article by Scott Elliott\",\"description\":\"\",\"media\":[{\"type\":\"image\",\"src\":\"http://www.316apps.com/lagrange.jpg\",\"href\":\"http://resurrectedliving.wordpress.com\"}]}",
						 self.title, self.currentURL];
	[dialog show];
	
}

#pragma mark Memory Cleanup

- (void)viewDidUnload {
	self.postGradesButton = nil;
    self.logoutButton = nil;
}

- (void)dealloc {
    [_session release];
	_session = nil;
	[_postGradesButton release];
	_postGradesButton = nil;
    [_logoutButton release];
	_logoutButton = nil;
    [_loginDialog release];
	_loginDialog = nil;
    [_facebookName release];
	_facebookName = nil;
    [super dealloc];
}




@end
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.