ios - Save data from textField into a file when the application has closed or terminated -


in application has view controller named "home" textfield. read applicationdidenterbackground , applicationwillterminate methods in appdelegate file. know how create, save, read data file.

my question is, how can nsstring "home" viewcontroller (that there store textfield data) appdelegate applicationdidenterbackground method , there things data?

you use nsnotificationcenter register notification in view controller fires off whenever enter applicationdidenterbackground or applicationwillterminate.

so in either of methods put like

[[nsnotificationcenter defaultcenter] postnotificationname:@"somedescriptivename" object:self userinfo:@{@"key" : @"value"}]; 

userinfo expects nsdicitonary , can pass type of object in there, in case dont need pass here viewcontroller, using means let view controller know app closing.

in view controller register notification this

[[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(methodtocall:) name:@"somedescriptivename" object:nil];  

then whenever appdelegate post notification, view controller registered listen fire off "methodtocall" can method right , takes in nsnotification lets access nsdicitonary carrying.

- (void)methodtocall:(nsnotification *)notif{ nslog(@"methodtocall fired data %@",[[notif userinfo]valueforkey:@"key"]);} 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -