Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems calling the delegate methods #11

Closed
delarge77 opened this issue Dec 2, 2012 · 2 comments
Closed

Problems calling the delegate methods #11

delarge77 opened this issue Dec 2, 2012 · 2 comments

Comments

@delarge77
Copy link

Everything is working fine , but after user gives the permission , my delegate methods are not called ...

Here is my entire class :

//
// CheckInViewController.m
// Lokaos
//
// Created by Andy Delarge on 15/08/12.
//
//

import "CheckInViewController.h"

import "Flurry.h"

import "FSQJSONObjectViewController.h"

import "Constantes.h"

@interface CheckInViewController ()<BZFoursquareRequestDelegate, BZFoursquareSessionDelegate>
@Property(nonatomic,readwrite,strong) BZFoursquare *foursquare;
@Property(nonatomic,strong) BZFoursquareRequest *request;
@Property(nonatomic,copy) NSDictionary *meta;
@Property(nonatomic,copy) NSArray *notifications;
@Property(nonatomic,copy) NSDictionary *response;

  • (void)updateView;
  • (void)cancelRequest;
  • (void)prepareForRequest;
  • (void)searchVenues;
  • (void)checkin;
  • (void)addPhoto;
    @EnD

enum {
kAuthenticationSection = 0,
kEndpointsSection,
kResponsesSection,
kSectionCount
};

enum {
kAccessTokenRow = 0,
kAuthenticationRowCount
};

enum {
kSearchVenuesRow = 0,
kCheckInRow,
kAddPhotoRow,
kEndpointsRowCount
};

enum {
kMetaRow = 0,
kNotificationsRow,
kResponseRow,
kResponsesRowCount
};

@implementation CheckInViewController
@synthesize foursquare = foursquare_;
@synthesize request = request_;
@synthesize meta = meta_;
@synthesize notifications = notifications_;
@synthesize response = response_;

  • (id)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
    self.foursquare = [[BZFoursquare alloc] initWithClientID:kClientID callbackURL:kCallbackURL];
    foursquare_.version = @"20111119";
    foursquare_.locale = [[NSLocale currentLocale] objectForKey:NSLocaleLanguageCode];
    foursquare_.sessionDelegate = self;
    }
    return self;
    }

  • (void)viewDidLoad
    {
    [super viewDidLoad];
    self.navigationController.navigationBar.tintColor = [UIColor blackColor];
    foursquare_.sessionDelegate = self;
    }

  • (void)viewWillAppear:(BOOL)animated {

    if (![foursquare_ isSessionValid]) {
    [foursquare_ startAuthorization];
    }

    [Flurry logEvent:@"CheckIn"];
    [super viewWillAppear:YES];

    [self viewDidLoad];
    }

  • (void)viewDidUnload
    {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    }

pragma mark - UITableView DataSource Methods

  • (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
    return 8;
    }

  • (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
    return 1;
    }

  • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {

    static NSString *cellIdentfier = @"cellIdentifier";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentfier];

    if (cell == nil)
    {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentfier];
    }

    cell.textLabel.textColor = [UIColor whiteColor];

    switch (indexPath.section) {
    case kAuthenticationSection:
    if (![foursquare_ isSessionValid]) {
    cell.textLabel.text = NSLocalizedString(@"Obtain Access Token", @"");
    } else {
    cell.textLabel.text = NSLocalizedString(@"Forget Access Token", @"");
    }
    break;
    case kResponsesSection:
    {
    id collection = nil;
    switch (indexPath.row) {
    case kMetaRow:
    collection = meta_;
    break;
    case kNotificationsRow:
    collection = notifications_;
    break;
    case kResponseRow:
    collection = response_;
    break;
    }
    if (!collection) {
    cell.textLabel.enabled = NO;
    cell.detailTextLabel.text = nil;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    } else {
    cell.textLabel.enabled = YES;
    NSUInteger count = [collection count];
    NSString *format = (count == 1) ? NSLocalizedString(@"(%lu item)", @"") : NSLocalizedString(@"(%lu items)", @"");
    cell.detailTextLabel.text = [NSString stringWithFormat:format, count];
    cell.selectionStyle = UITableViewCellSelectionStyleBlue;
    }
    }
    break;
    }

    return cell;
    }

  • (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    return 80;
    }

pragma mark -

pragma mark BZFoursquareRequestDelegate

  • (void)requestDidFinishLoading:(BZFoursquareRequest *)request {
    self.meta = request.meta;
    self.notifications = request.notifications;
    self.response = request.response;
    self.request = nil;
    [self updateView];
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
    }
  • (void)request:(BZFoursquareRequest *)request didFailWithError:(NSError *)error {
    NSLog(@"%s: %@", PRETTY_FUNCTION, error);
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:[[error userInfo] objectForKey:@"errorDetail"] delegate:nil cancelButtonTitle:NSLocalizedString(@"OK", @"") otherButtonTitles:nil];
    [alertView show];
    self.meta = request.meta;
    self.notifications = request.notifications;
    self.response = request.response;
    self.request = nil;
    [self updateView];
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
    }

pragma mark -

pragma mark BZFoursquareSessionDelegate

  • (void)foursquareDidAuthorize:(BZFoursquare *)foursquare {
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:kAccessTokenRow inSection:kAuthenticationSection];
    NSArray *indexPaths = [NSArray arrayWithObject:indexPath];
    [self.tableView reloadData];
    [self.tableView reloadRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone];
    }
  • (void)foursquareDidNotAuthorize:(BZFoursquare *)foursquare error:(NSDictionary *)errorInfo {
    NSLog(@"%s: %@", PRETTY_FUNCTION, errorInfo);
    }

pragma mark Anonymous category

  • (void)updateView {
    if ([self isViewLoaded]) {
    NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
    [self.tableView reloadData];
    if (indexPath) {
    [self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
    }
    }
    }
  • (void)cancelRequest {
    if (request_) {
    request_.delegate = nil;
    [request_ cancel];
    self.request = nil;
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
    }
    }
  • (void)prepareForRequest {
    [self cancelRequest];
    self.meta = nil;
    self.notifications = nil;
    self.response = nil;
    }
  • (void)searchVenues {
    [self prepareForRequest];
    NSDictionary *parameters = [NSDictionary dictionaryWithObjectsAndKeys:@"40.7,-74", @"ll", nil];
    self.request = [foursquare_ requestWithPath:@"venues/search" HTTPMethod:@"GET" parameters:parameters delegate:self];
    [request_ start];
    [self updateView];
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
    }
  • (void)checkin {
    [self prepareForRequest];
    NSDictionary *parameters = [NSDictionary dictionaryWithObjectsAndKeys:@"4d341a00306160fcf0fc6a88", @"venueId", @"public", @"broadcast", nil];
    self.request = [foursquare_ requestWithPath:@"checkins/add" HTTPMethod:@"POST" parameters:parameters delegate:self];
    [request_ start];
    [self updateView];
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
    }
  • (void)addPhoto {
    [self prepareForRequest];
    NSURL *photoURL = [[NSBundle mainBundle] URLForResource:@"TokyoBa-Z" withExtension:@"jpg"];
    NSData *photoData = [NSData dataWithContentsOfURL:photoURL];
    NSDictionary *parameters = [NSDictionary dictionaryWithObjectsAndKeys:photoData, @"photo.jpg", @"4d341a00306160fcf0fc6a88", @"venueId", nil];
    self.request = [foursquare_ requestWithPath:@"photos/add" HTTPMethod:@"POST" parameters:parameters delegate:self];
    [request_ start];
    [self updateView];
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
    }
  • (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }

@EnD

I dont know what Im doing wrong since I set myself as the delegate, and implement them ...
Thanks for any help !

@baztokyo
Copy link
Collaborator

Does our sample app work? The app works on our environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@baztokyo @delarge77 and others