passing facebook info between viewsController

i have been looking on the net to see whether i need to place the delegates in the profileViewController (which is the view the info is going to) or i need the delegates in the login/signup viewControllers i dont know how to pass the info profilePicture, name, login status please help,

EDIT::

i was able to pass the user.name through my protocols but i can not pass FBProfilePictureView

ViewController.h

#import <UIKit/UIKit.h>
#import <FacebookSDK/FacebookSDK.h>


@protocol passNames <NSObject>

- (void)setFBName: (NSString *)FBName;
- (void)setFBProfilePicture: (id<FBGraphUser>)FBPicture;

@end

@interface ViewController : UIViewController <FBLoginViewDelegate>


@property (weak) id <passNames> delegate;
@property (strong, nonatomic) NSString *FBNamePass;
@property (strong, nonatomic) FBProfilePictureView *FBProfilePicture;

@end

ViewController.m

#import "ViewController.h"
#import "NeXtViewController.h"

@interface ViewController ()

@property (strong, nonatomic) IBOutlet UILabel *statusLabel;
@property (strong, nonatomic) IBOutlet UILabel *nameLabel;
@property (strong, nonatomic) IBOutlet FBProfilePictureView *profilePictureView;


@end

@implementation ViewController

@synthesize delegate, FBNamePass, FBProfilePicture;

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.



// Create a FBLoginView to log the user in with basic, email and likes permissions
// you should always ask for basic permissions when loggin the user in
FBLoginView *loginView = [[FBLoginView alloc] initWithReadPermissions:@[@"basic_info",@"email",@"user_likes"]];

// set this loginUIViewCOntroller to be the loginView button's delegate
loginView.delegate = self;


// align the button in the center horizontally
loginView.frame = CGRectMake(25, 299, 271, 50);

// add the button to the view
[self.view addSubview:loginView];

//[self pushViewController];


}

-(void)viewDidAppear:(BOOL)animated
{

}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

// this method will be called when the user information has been fetched
- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView user:(id<FBGraphUser>)user
{
self.nameLabel.text = user.name;
//self.profilePictureView.profileID = user.id;


//    FBProfilePicture.profileID = user.id;
//    NSLog(@"%@ FB", FBProfilePicture.class);
//    FBNamePass = user.name;
//    NSLog(@"%@ user", FBNamePass);
[self pushViewController:user.name andProfilePicture:user];
}


- (BOOL)isUser:(id<FBGraphUser>)firstUser equalToUser:(id<FBGraphUser>)secondUser {
return
[firstUser.id isEqual:secondUser.id] &&
[firstUser.name isEqual:secondUser.name] &&
[firstUser.first_name isEqual:secondUser.first_name] &&
[firstUser.middle_name isEqual:secondUser.middle_name] &&
[firstUser.last_name isEqual:secondUser.last_name];
}



// implement the loginViewShowingLoggedInUser: delegate method to modify your app's UI for a logged-in user experoience
- (void)loginViewShowingLoggedInUser:(FBLoginView *)loginView
{
self.statusLabel.text = @"Logged in";

if ([self.statusLabel.text isEqualToString:@"Logged in"]) {
    //NeXtViewController *n = [self.storyboard instantiateViewControllerWithIdentifier:@"NeXt"];
    //[self.navigationController pushViewController:n animated:NO];

}
}

// implement the loginViewShowingLoggedOutUser: delegate method to modify your app's UI for a logged-out user experoience
- (void)loginViewShowingLoggedOutUser:(FBLoginView *)loginView
{
self.profilePictureView.profileID = nil;
self.nameLabel.text = @"";
self.statusLabel.text = @"You're not logged in";
}

// You need to override loginView:handleError in order to handle possible errors that can occur during login
- (void)loginView:(FBLoginView *)loginView handleError:(NSError *)error
{
NSString *alertMessage, *alertTitle;

// If the user should perform an action outside of you app to recover,
// the SDK will provide a message for the user, you just need to surface it.
// This conveniently handles cases like Facebook password change or unverified Facebook accounts.
if ([FBErrorUtility shouldNotifyUserForError:error]) {
    alertMessage = [FBErrorUtility userMessageForError:error];
    alertTitle = @"Facebook Error";

    // This code will handle session closures since that happen outside of the app.
    // You can take a look at our error handling guide to know more about it
    // https://developers.facebook.com/docs/ios/errors
} else if ([FBErrorUtility errorCategoryForError:error] == FBErrorCategoryAuthenticationReopenSession) {
    alertTitle = @"Session Error";
    alertMessage = @"Your current session is no longer valid. Please log in again.";

    // If the user has cancelled a login, we will do nothing.
    // You can also choose to show the user a message if cancelling login will result in
    // the user not being able to complete a task they had initiated in your app
    // (like accessing FB-stored information or posting to Facebook)
} else if ([FBErrorUtility errorCategoryForError:error] == FBErrorCategoryUserCancelled) {
    NSLog(@"user cancelled login");

    // For simplicity, this sample handles other errors with a generic message
    // You can checkout our error handling guide for more detailed information
    // https://developers.facebook.com/docs/ios/errors
} else {
    alertTitle = @"Something went wrong";
    alertMessage = @"Please try again later";
    NSLog(@"Unexpected error:%@",error);
}

if (alertMessage) {
    [[[UIAlertView alloc] initWithTitle:alertTitle
                                message:alertMessage
                               delegate:nil
                      cancelButtonTitle:@"ok"
                      otherButtonTitles:nil] show];
}




}

- (void)pushViewController:(NSString *)user andProfilePicture:(id<FBGraphUser>)profilePicture
{
NeXtViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"NeXt"];
[controller setFBNameString:user];
//controller.profilePicture = profilePicture;
[controller setFBProfilePicture:profilePicture];
NSLog(@"%@",profilePicture);
[self.navigationController pushViewController:controller animated:NO];
}

@end

NeXtViewController.h

#import <UIKit/UIKit.h>
#import <FacebookSDK/FacebookSDK.h>
#import "ViewController.h"

@interface NeXtViewController : UIViewController <passNames>
{
ViewController *view;
}


@property (strong,nonatomic) NSString *FBNameString;
@property (strong, nonatomic) FBProfilePictureView *profilePicture;

@property (weak, nonatomic) IBOutlet FBProfilePictureView *FBProfilePictureView;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;


- (IBAction)FBLogOut:(id)sender;

@end

NeXtViewController.m

#import "NeXtViewController.h"

@interface NeXtViewController ()

@end

@implementation NeXtViewController

@synthesize FBNameString = _FBNameString, profilePicture = _profilePicture;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Custom initialization
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.

view = [[ViewController alloc] init];
[view setDelegate:self];
self.nameLabel.text = _FBNameString;
//self.FBProfilePictureView.profileID = _profilePicture.profileID;
NSLog(@"%@ %@", self.FBProfilePictureView.class, self.FBNameString.class);

self.navigationItem.hidesBackButton = YES;
}

-(void)viewDidAppear:(BOOL)animated
{

}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}


- (void)setFBName:(NSString *)FBName
{
_FBNameString = FBName;
}

- (void)setFBProfilePicture:(id<FBGraphUser>)FBPicture
{
self.FBProfilePictureView.profileID = FBPicture.id;
}

- (IBAction)FBLogOut:(id)sender
{
[FBSession.activeSession closeAndClearTokenInformation];
if (FBSessionDidBecomeClosedActiveSessionNotification) {
    ViewController *views = [self.storyboard instantiateViewControllerWithIdentifier:@"View"];
    [self.navigationController pushViewController:views animated:NO];
    views.navigationItem.hidesBackButton = YES;
}
}


@end

Answers


You don't need delegates in my opinion (from what I gather from your question). What you can do, is get a reference to the 'profileViewController' from your 'login/signup viewControllers' and just pass some information to them. Let's take the assumption you're using the storyboard and segues. In your profileViewController.h you would create a few properties like so:

@interface profileViewController

@property(nonatomic) UIImage* profilePicture;
@property(nonatomic) NSString* name;
@property(nonatomic) NSString* loginStatus;

//all your methods and properties...

@end

Then in your login/signup view controllers, find a way to find the profileViewController:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the profile view controller from segue and cast it
    profileViewController* profileVC = (profileViewController*)[segue destinationViewController];

    // Set the properties in the profile VC Class
    [profileVC setProfilePicture:myImage];
    [profileVC setName:myName];
    [profileVC setLoginStatus:myLoginStatus];
}

and then whenever the 'viewDidLoad' or 'init' is called in the profileViewController, the properties should be set and ready to use! It doesn't have to be a segue you are using, just any way of accessing the profileViewController before you use it.


Tried to set your data into NSUserDefault it is easy to use and share data among multiple classes is simple using NSUserDefault.

AppDelegate.m

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];

Saving

 AppDelegate * degate=(AppDelegate *)[[UIApplication sharedApplication]delegate];
    delegate.prefs = [NSUserDefaults standardUserDefaults];

// saving an NSString
[delegate.prefs setObject:@"TextToSave" forKey:@"keyToLookupString"];

// saving an NSInteger
[delegate.prefs setInteger:42 forKey:@"integerKey"];

[delegate.prefs synchronize];

Retrieving

delegate.prefs = [NSUserDefaults standardUserDefaults];

// getting an NSString
NSString *myString = [delegate.prefs stringForKey:@"keyToLookupString"];

// getting an NSInteger
NSInteger myInt = [delegate.prefs integerForKey:@"integerKey"];

And define your NSUSserDefault in your AppDelegate and share using AppDelageate object and and whatever your data among multiple classes.

Tried this one


Need Your Help

Calling and consuming a JBoss Web Service from JavaScript (AJAX)

java javascript ajax web-services jboss

I am fiddling around with JBOSS's Web Services, and I have created the following: