ios - passing facebook info between viewsController -


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

edit::

i able pass user.name through protocols 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]; // additional setup after loading view, typically nib.    // create fbloginview log user in basic, email , likes permissions // should ask basic permissions when loggin user in fbloginview *loginview = [[fbloginview alloc] initwithreadpermissions:@[@"basic_info",@"email",@"user_likes"]];  // set loginuiviewcontroller loginview button's delegate loginview.delegate = self;   // align button in center horizontally loginview.frame = cgrectmake(25, 299, 271, 50);  // add button view [self.view addsubview:loginview];  //[self pushviewcontroller];   }  -(void)viewdidappear:(bool)animated {  }  - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. }  // method called when 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 loginviewshowingloggedinuser: delegate method modify app's ui 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 loginviewshowingloggedoutuser: delegate method modify app's ui logged-out user experoience - (void)loginviewshowingloggedoutuser:(fbloginview *)loginview { self.profilepictureview.profileid = nil; self.namelabel.text = @""; self.statuslabel.text = @"you're not logged in"; }  // need override loginview:handleerror in order handle possible errors can occur during login - (void)loginview:(fbloginview *)loginview handleerror:(nserror *)error { nsstring *alertmessage, *alerttitle;  // if user should perform action outside of app recover, // sdk provide message user, need surface it. // conveniently handles cases facebook password change or unverified facebook accounts. if ([fberrorutility shouldnotifyuserforerror:error]) {     alertmessage = [fberrorutility usermessageforerror:error];     alerttitle = @"facebook error";      // code handle session closures since happen outside of app.     // can take @ our error handling guide know more     // https://developers.facebook.com/docs/ios/errors } else if ([fberrorutility errorcategoryforerror:error] == fberrorcategoryauthenticationreopensession) {     alerttitle = @"session error";     alertmessage = @"your current session no longer valid. please log in again.";      // if user has cancelled login, nothing.     // can choose show user message if cancelling login result in     // user not being able complete task had initiated in app     // (like accessing fb-stored information or posting facebook) } else if ([fberrorutility errorcategoryforerror:error] == fberrorcategoryusercancelled) {     nslog(@"user cancelled login");      // simplicity, sample handles other errors generic message     // can checkout our error handling guide 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]; // additional setup after loading 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 resources can 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 

you don't need delegates in opinion (from gather question). can do, reference 'profileviewcontroller' 'login/signup viewcontrollers' , pass information them. let's take assumption you're using storyboard , segues. in profileviewcontroller.h create few properties so:

@interface profileviewcontroller  @property(nonatomic) uiimage* profilepicture; @property(nonatomic) nsstring* name; @property(nonatomic) nsstring* loginstatus;  //all methods , properties...  @end 

then in login/signup view controllers, find way find profileviewcontroller:

-(void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender {     // profile view controller segue , cast     profileviewcontroller* profilevc = (profileviewcontroller*)[segue destinationviewcontroller];      // set properties in profile vc class     [profilevc setprofilepicture:myimage];     [profilevc setname:myname];     [profilevc setloginstatus:myloginstatus]; } 

and whenever 'viewdidload' or 'init' called in profileviewcontroller, properties should set , ready use! doesn't have segue using, way of accessing profileviewcontroller before use it.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -