Thread never gets to fbDidLogin and accessToken is null when appDidBecomeActive and shows view
Thread never gets to fbDidLogin and accessToken is null when appDidBecomeActive and shows view
- Subject: Thread never gets to fbDidLogin and accessToken is null when appDidBecomeActive and shows view
- From: Michele Cleary <email@hidden>
- Date: Thu, 03 May 2012 17:09:32 -0700 (PDT)
I'm working on an app that uses the FB static sdk corrected for ARC. The user logs in, but the thread never gets to fbDidLogin. Also, when I get the accessToken, it's null. I really hope someone sees an issue with the following:
my ImportPic2VC.m: *********************************************************
#import "ImportPic2ViewController.h"
@interfaceImportPic2ViewController()
@property (nonatomic, strong) NSMutableDictionary * userPermissions;
@end
@implementation ImportPic2ViewController
@synthesizefacebook;
@synthesize userPermissions = _userPermissions;
- (void)viewDidLoad
{
[superviewDidLoad];
//ImportPic2AppDelegate *delegate = (ImportPic2AppDelegate *)[[UIApplication sharedApplication] delegate];
//[[delegate facebook] = [[Facebook alloc] initWithAppId:@"224207854355440" andDelegate:self];
facebook= [[Facebookalloc] initWithAppId:@"224207854355440"andDelegate:self];
NSUserDefaults*defaults = [NSUserDefaultsstandardUserDefaults];
if ([defaults objectForKey:@"FBAccessTokenKey"]
&& [defaults objectForKey:@"FBExpirationDateKey"]) {
facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
}
if(![facebookisSessionValid]) {
[facebook authorize:nil];
}
self.userPermissions= [[NSMutableDictionaryalloc] initWithCapacity:1];
[self.userPermissionssetObject:@"1"forKey:@"publish_stream"];
[self.userPermissionssetObject:@"1"forKey:@"publish_actions"];
[self.userPermissionssetObject:@"1"forKey:@"photo_upload"];
}
- (IBAction)ImageButtonPressed:(id)sender {
NSLog(@"ImageButtonPressed");
NSUserDefaults*defaults = [NSUserDefaultsstandardUserDefaults];
[defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
[defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
NSLog(@"accessToken:%@", facebook.accessToken);
[defaults synchronize];
[selfapiGraphUserPermissions];
}
- (void)apiGraphUserPermissions {
/*
* This method is called to store the photo permissions
* in the app session after the permissions have been updated.
*/
[facebookrequestWithGraphPath:@"me/permissions"andDelegate:self];
[selfapiGraphUserPhotosPost];
}
/*
* Graph API: Upload a photo. By default, when using me/photos the photo is uploaded
* to the application album which is automatically created if it does not exist.
*/
- (void)apiGraphUserPhotosPost {
NSLog(@"This is important. Should see this logged. MDC");
//check if need permissions or not
//this is what checkin one does//////////////////////
//HackbookAppDelegate *delegate = (HackbookAppDelegate *)[[UIApplication sharedApplication] delegate];
//if ([[delegate userPermissions] objectForKey:@"user_checkins"]) {
// [self apiGraphUserCheckins];
//} else {
// currentAPICall = kDialogPermissionsCheckinForRecent;
// [self apiPromptCheckinPermissions];
//}
/////////////////////////////////
//[self showActivityIndicator];
//currentAPICall = kAPIGraphUserPhotosPost;
//HackbookAppDelegate *delegate = (HackbookAppDelegate *)[[UIApplication sharedApplication] delegate];
//switch this over to be chg permission if need it
//
//if ([self.userPermissions objectForKey:@"photo_upload"]) {
//we're where we need to be with permissions//[self apiGraphUserPhotosPost]; //MDC
// NSLog(@"That's nice. Nothing to change.");
//} else {
//add needed permissions, with prompt
//currentAPICall = kDialogPermissionsCheckinForRecent; //done already
[selfapiPromptPhotoAddPermissions]; //MDC
//}
//end of new MDC code
// Download a sample photo ??MDC - sub my photo in here later
NSUserDefaults*defaults = [NSUserDefaultsstandardUserDefaults];
[defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
[defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
[defaults synchronize];
NSURL*url = [NSURLURLWithString:@"http://www.facebook.com/images/devsite/iphone_connect_btn.jpg"];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [[UIImage alloc] initWithData:data];
NSMutableDictionary*params = [NSMutableDictionarydictionaryWithObjectsAndKeys:
img, @"picture",
nil];
//[img release];
[facebookrequestWithGraphPath:@"me/photos"
andParams:params
andHttpMethod:@"POST"
andDelegate:self];
//[img release];
}
/*
* Dialog: Authorization to grant the app photo add permissions. - MDC
*/
- (void)apiPromptPhotoAddPermissions {
NSArray*photoAddPermissions = [[NSArrayalloc] initWithObjects:@"publish_stream", @"publish_actions", @"photo_upload", nil]; //MDC
[facebook authorize:photoAddPermissions];
}
- (void)viewDidUnload
{
[superviewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if([[UIDevicecurrentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return(interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
return YES;
}
}
- (BOOL)handleOpenURL:(NSURL *)url
{
return [facebook handleOpenURL:url];
}
// For iOS 4.2+ support
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [facebook handleOpenURL:url];
}
- (void)fbDidLogin {
NSUserDefaults*defaults = [NSUserDefaultsstandardUserDefaults];
[defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
[defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
[defaults synchronize];
[facebookdialog:@"feed"andDelegate:self];
}
- (void) fbDidLogout {
// Remove saved authorization information if it exists
NSUserDefaults*defaults = [NSUserDefaultsstandardUserDefaults];
if ([defaults objectForKey:@"FBAccessTokenKey"]) {
[defaults removeObjectForKey:@"FBAccessTokenKey"];
[defaults removeObjectForKey:@"FBExpirationDateKey"];
[defaults synchronize];
}
}
-(void)fbDidExtendToken:(NSString *)accessToken expiresAt:(NSDate *)expiresAt {
NSLog(@"token extended");
NSUserDefaults*defaults = [NSUserDefaultsstandardUserDefaults];
[defaults setObject:accessToken forKey:@"FBAccessTokenKey"];
[defaults setObject:expiresAt forKey:@"FBExpirationDateKey"];
[defaults synchronize];
}
-(void)fbDidNotLogin:(BOOL)cancelled
{
NSLog(@"did not login");
}
-(void)request:(FBRequest *)request didLoad:(id)result
{
if ([result isKindOfClass:[NSArray class]]) {
//result = [result objectAtIndex:0];
self.userPermissions = [[result objectForKey:@"data"] objectAtIndex:0];
}
NSLog(@"Result of API call: %@", result);
}
-(void)request:(FBRequest *)request didFailWithError:(NSError *)error
{
NSLog(@"Failed with error: %@", [error localizedDescription]);
NSLog(@"Err details: %@", [error description]);
}
/*
- (void)storeAuthData:(NSString *)accessToken expiresAt:(NSDate *)expiresAt {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:accessToken forKey:@"FBAccessTokenKey"];
[defaults setObject:expiresAt forKey:@"FBExpirationDateKey"];
[defaults synchronize];
}*/
@end
my ImportPic2VC.h: *********************************************
#import <UIKit/UIKit.h>
#import "FBConnect.h"
@interface ImportPic2ViewController : UIViewController <FBRequestDelegate,
FBDialogDelegate,
FBSessionDelegate>{
Facebook *facebook;
}
@property(nonatomic, retain) Facebook*facebook;
@end
my ImportPic2AppDelegate.m******************************************
#import "ImportPic2AppDelegate.h"
#import "ImportPic2ViewController.h"
//#import "FBConnect.h"
//@interface FacebookAppDelegate : UIResponder <UIApplicationDelegate>
//@end
@implementation ImportPic2AppDelegate
//@synthesize facebook;
//@synthesize userPermissions;
@synthesize viewController = _viewController;
@synthesize window = _window;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//ImportPic2ViewController *importPic2VC = [[ImportPic2ViewController alloc] init];
//UINavigationController *navController = [[UINavigationController alloc] initWith
//self.viewController = [[FacebookV
//facebook = [[Facebook alloc] initWithAppID:@"224207854355440" andDelegate:(id)self];
//self.window.rootViewController = self.viewController;
//[self.window makeKeyAndVisible];
returnYES;
}
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return[[_viewControllerfacebook] handleOpenURL:url];
}
// For iOS 4.2+ support
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return[[_viewControllerfacebook] handleOpenURL:url];
}
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
- (void)fbDidLogin {
//[self showLoggedIn];
//ImportPicAppDelegate *delegate = (ImportPicAppDelegate *)[[UIApplication sharedApplication] delegate];
//[self storeAuthData:[[delegate facebook] accessToken] expiresAt:[[delegate facebook] expirationDate]];
//NSLog(@"Permissions granted.");
//[pendingApiCallsController userDidGrantPermission];
}
-(void)fbDidExtendToken:(NSString *)accessToken expiresAt:(NSDate *)expiresAt {
NSLog(@"token extended");
//[self storeAuthData:accessToken expiresAt:expiresAt];
}
/**
* Called when the user canceled the authorization dialog.
*/
-(void)fbDidNotLogin:(BOOL)cancelled {
NSLog(@"permission not granted");
//[pendingApiCallsController userDidNotGrantPermission];
}
/**
* Called when the request logout has succeeded.
*/
- (void)fbDidLogout {
//pendingApiCallsController = nil;
// Remove saved authorization information if it exists and it is
// ok to clear it (logout, session invalid, app unauthorized)
NSUserDefaults*defaults = [NSUserDefaultsstandardUserDefaults];
[defaults removeObjectForKey:@"FBAccessTokenKey"];
[defaults removeObjectForKey:@"FBExpirationDateKey"];
[defaults synchronize];
//[self showLoggedOut];
}
/**
* Called when the session has expired.
*/
- (void)fbSessionInvalidated {
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:@"Auth Exception"
message:@"Your session has expired."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil,
nil];
[alertView show];
//[alertView release];
[selffbDidLogout];
}
#pragma mark - FBRequestDelegate Methods
/**
* Called when the Facebook API request has returned a response.
*
* This callback gives you access to the raw response. It's called before
* (void)request:(FBRequest *)request didLoad:(id)result,
* which is passed the parsed response object.
*/
- (void)request:(FBRequest *)request didReceiveResponse:(NSURLResponse *)response {
//NSLog(@"received response");
}
/**
* Called when a request returns and its response has been parsed into
* an object.
*
* The resulting object may be a dictionary, an array or a string, depending
* on the format of the API response. If you need access to the raw response,
* use:
*
* (void)request:(FBRequest *)request
* didReceiveResponse:(NSURLResponse *)response
*/
- (void)request:(FBRequest *)request didLoad:(id)result {
if ([result isKindOfClass:[NSArray class]]) {
result = [result objectAtIndex:0];
}
// This callback can be a result of getting the user's basic
// information or getting the user's permissions.
if ([result objectForKey:@"name"]) {
// If basic information callback, set the UI objects to
// display this.
/*
nameLabel.text = [result objectForKey:@"name"];
// Get the profile image
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[result objectForKey:@"pic"]]]];
// Resize, crop the image to make sure it is square and renders
// well on Retina display
float ratio;
float delta;
float px = 100; // Double the pixels of the UIImageView (to render on Retina)
CGPoint offset;
CGSize size = image.size;
if (size.width > size.height) {
ratio = px / size.width;
delta = (ratio*size.width - ratio*size.height);
offset = CGPointMake(delta/2, 0);
} else {
ratio = px / size.height;
delta = (ratio*size.height - ratio*size.width);
offset = CGPointMake(0, delta/2);
}
CGRect clipRect = CGRectMake(-offset.x, -offset.y,
(ratio * size.width) + delta,
(ratio * size.height) + delta);
UIGraphicsBeginImageContext(CGSizeMake(px, px));
UIRectClip(clipRect);
[image drawInRect:clipRect];
UIImage *imgThumb = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[profilePhotoImageView setImage:imgThumb];
*/
//[self apiGraphUserPermissions];
} else {
// Processing permissions information
//ImportPicAppDelegate *delegate = (ImportPicAppDelegate *)[[UIApplication sharedApplication] delegate];
//[delegate setUserPermissions:[[result objectForKey:@"data"] objectAtIndex:0]];
}
}
/**
* Called when an error prevents the Facebook API request from completing
* successfully.
*/
- (void)request:(FBRequest *)request didFailWithError:(NSError *)error {
NSLog(@"Err message: %@", [[error userInfo] objectForKey:@"error_msg"]);
NSLog(@"Err code: %d", [error code]);
}
@end
my ImportPic2AppDelegate.h************************************************
#import <UIKit/UIKit.h>
#import "FBConnect.h"
#import "ImportPic2ViewController.h"
@interfaceImportPic2AppDelegate : UIResponder<UIApplicationDelegate, UIAlertViewDelegate>
{
//Facebook *facebook;
//NSMutableDictionary *userPermissions;
}
@property(strong, nonatomic) UIWindow*window;
@property(strong, nonatomic) ImportPic2ViewController*viewController;
//@property (nonatomic, retain) Facebook *facebook;
//@property (nonatomic, retain) NSMutableDictionary *userPermissions;
@end
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden