passing appdelegate data to viewcontroller - iphone

I have the following method in my AppDelegate.m. I want the value of deviceToken in my UIViewController
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
NSLog(#"My token is: %#", deviceToken);
ViewController *viewController = [[ViewController alloc]initWithNibName:#"ViewController" bundle:nil];
viewController.tokenStr = [NSString stringWithFormat:#"%#",deviceToken];
}
but when I display NSLog(#"%#",tokenStr); in UIViewController I'm getting (NULL).
how can I get the value in my UIViewController?

In AppDelegate, you can save the deviceToken value in NSUserDefaults like
[[NSUserDefaults standardUserDefaults] setObject:deviceToken forKey:#"DeviceToken"];
[[NSUserDefaults standardUserDefaults] synchronize];
and Retrieve that value from any View Controller using
[[NSUserDefaults standardUserDefaults] objectForKey:#"DeviceToken"];

You can have a reference to AppDelegate with [UIApplication sharedApplication].delegate.
It depends on your needs. Something like a token you really should save in NSUserDefaults, it was designed for saving user's credentials and tokens. But if you want to use all public properties and methods of AppDelegate in any viewController, you can use it's delegate.
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
NSString *token = appDelegate.token;

In AppDelegate.m class:
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
NSLog(#"My token is: %#", deviceToken);
NSString *device = [deviceToken description];
device = [device stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:#"<>"]];
device = [device stringByReplacingOccurrencesOfString:#" " withString:#""];
NSLog(#"My device is: %#", device);
[[NSUserDefaults standardUserDefaults] setObject:device forKey:#"MyAppDeviceToken"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
In ViewController class, inside viewDidLoad method:
[super viewDidLoad];
NSString *deviceToken = [[NSUserDefaults standardUserDefaults] objectForKey:#"MyAppDeviceToken"];
NSLog(#"device token in controller: %# ", deviceToken);
This is working perfectly in my device. Happy Coding !! :)

Related

How to Get Device Token in didFinishLaunchingWithOptions

I am calling device token in my first viewcontroller. And I cant get result because Device token is null. Here below is my code in appdelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeBadge];
return YES;
}
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
token = [[deviceToken description] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:#"<>"]];
token = [token stringByReplacingOccurrencesOfString:#" " withString:#""];
NSLog(#"Device Token ---%#", token);
[[NSUserDefaults standardUserDefaults] setObject:token forKey:#"DeviceToken"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
When I am calling in Viewcontroller :
NSString *token= [[NSUserDefaults standardUserDefaults] objectForKey:#"DeviceToken"];
token is null.
NSString *device = [deviceToken description];
device = [device stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:#"<>"]];
device = [device stringByReplacingOccurrencesOfString:#" " withString:#""];
NSLog(#"My device is: %#", device);
This worked perfectly for me in my device.
Refer to Kulss' answer in this SO Answer:
How can I convert my device token (NSData) into an NSString?
You should be parsing the bytes not the description.
First
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Add this in Application.h
try this one my friend....
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
#if !TARGET_IPHONE_SIMULATOR
// Prepare the Device Token for Registration (remove spaces and < >)
token = [[[[devToken description]
stringByReplacingOccurrencesOfString:#"<"withString:#""]
stringByReplacingOccurrencesOfString:#">" withString:#""]
stringByReplacingOccurrencesOfString: #" " withString: #""];
NSLog(#"%#",token);
[[NSUserDefaults standardUserDefaults] setObject:token forKey:#"deviceToken"];
[[NSUserDefaults standardUserDefaults] synchronize];
#endif
}
/**
* Failed to Register for Remote Notifications
*/
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
#if !TARGET_IPHONE_SIMULATOR
NSLog(#"Error in registration. Error: %#", error);
#endif
}
Happy Coding!!!!
Add two methods didRegister and didFailToRegister, and confirm are u getting a call in didRegister or in didFailedToRegister.
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
NSLog(#"Device Token=> %#",deviceToken);
//Parse your device toke
}
-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
NSLog(#"Error in registration. Error: %#", error.description);
}
and assure are u getting succesfully ur device token. Or u r failed to registerForRemote...
You can try this one
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*) deviceToken {
NSString *pushToken = [deviceToken description];
pushToken = [pushToken stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:#"<>"]];
[[NSUserDefaults standardUserDefaults] setObject:pushToken forKey:#"device_token_data"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
May be help you.
First register notification in then you will get toke in didRegisterRemoteNotification
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
self.strdeviceToken=[[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:#"<>"]];
self.strdeviceToken = [self.strdeviceToken stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
self.strdeviceToken=[self.strdeviceToken stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
}
You should check your provisioning profile. Also the App should be configured for push notification on developer portal.
Perform these steps for doing so.
Enable push notification for your Application Identifier on Developer portal.
regenerate the provisioning profile.
Download and install new provisioning profile.
Build and run.
It will work.
try this one..
after your transactions completed, you want token number in the view controller. so for that try to make or change root view controller again in appDelegate by the method like this in AppDelegate.m.
-(void)changeRootView
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
// Override point for customization after application launch.
self.viewController = [[[ViewController alloc] initWithNibName:#"ViewController" bundle:nil] autorelease];
//Adding navigation controller to the main view.
[navigationController release];
navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
}
in this method
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
this statement is helped to call didRegisterForRemoteNotificationsWithDeviceToken again and you can store the token in some object like NSUserDefaults and you can use it in your viewController. It works for me. you can try this. Best luck.

Save the username & password after login for the first time and not to ask again

I am developing one ios app, in that I need to enter company-code and accesscode to login. After login for the first time with the access code, We cannot prefer to ask for accesscode again when we open the application. I mean I need to save the preferences.
And my code is here
- (IBAction)loginClicked:(id)sender {
#try {
if([[txtsecurecode text] isEqualToString:#""] || [[OrganizationCode text] isEqualToString:#""] ) {
[self alertStatus:#"Please enter Access code" :#"Login Failed!":0];
} else {
NSString *post =[[NSString alloc] initWithFormat:#"txtsecurecode=%# #&password=%#",[txtsecurecode text],[OrganizationCode text]];
NSLog(#"PostData: %#",post);
NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"http://mycompany.com/AccountService/security/ValidateAccess?accesscode=%#&companycode=%#&type=1", txtsecurecode.text, OrganizationCode.text]];
[[ NSUserDefaults standardUserDefaults] setValue:OrganizationCode forKey:#"OrganizationCode"];
[[ NSUserDefaults standardUserDefaults] setValue:txtsecurecode forKey:#"txtsecurecode"];
[[NSUserDefaults standardUserDefaults] synchronize];
txtsecurecode = [[NSUserDefaults standardUserDefaults] objectForKey:#"txtsecurecode"];
OrganizationCode = [[NSUserDefaults standardUserDefaults] objectForKey:#"OrganizationCode"];
// NSString *num = [[NSUserDefaults standardUserDefaults] stringForKey:#"txtsecurecode"];
NSString *responseData = [[NSString alloc]initWithData:[NSData dataWithContentsOfURL:url] encoding:NSUTF8StringEncoding];
if([responseData isEqualToString:#""]){
[self alertStatus:#"Please enter valid Access Code" :#"Login Failed !" :0];
}
else
{
responseData = [responseData stringByReplacingOccurrencesOfString:#" "" " withString:#""];
responseData = [responseData stringByReplacingOccurrencesOfString:#"\\" withString:#""];
NSString* encodedString = [responseData stringByReplacingPercentEscapesUsingEncoding:
NSUTF8StringEncoding];
NSLog(#"Response ==> %#" ,encodedString);
UIWebView *webView;
webView = [[UIWebView alloc] initWithFrame:CGRectMake(0,0, 320, 470)];
webView.backgroundColor = [UIColor clearColor];
webView.opaque = NO;
[webView setDelegate:self];
NSString* urlTwo = [[encodedString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]
stringByReplacingOccurrencesOfString:#"%22" withString:#""];
NSURL *url2;
if([urlTwo hasPrefix:#"http://"]){
url2 = [NSURL URLWithString:urlTwo];
}else{
url2 = [NSURL URLWithString:[NSString stringWithFormat:#"http://%#" , urlTwo]];
}
NSLog(#"url2:%#", url2);
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url2];
[webView loadRequest:requestObj];
[[self view] addSubview:webView];
}
}
}
#catch (NSException * e) {
NSLog(#"Exception: %#", e);
[self alertStatus:#"Login Failed." :#"Login Failed!" :0];
}
}
I had used NSUserDefaults method to save the login credentials but it is not working. Credentials are not saving, again the app is asking for credentials.
try this
when you successfull login then save it in NSUserDefaults
NSUserDefaults *status=[NSUserDefaults standardUserDefaults];
[status setObject:#"1" forKey:#"Login"];
Next time only check
NSUserDefaults *objUserDefaults = [NSUserDefaults standardUserDefaults];
NSString *strSuccess=[objUserDefaults objectForKey:#"Login"];
if ([strSuccess isEqualToString:#"1"]) {
// just push the next view.
}
else {
// open login screen
}
OR Next option, if you care about security, the keychain.
Edit
.h file
NSUserDefaults *objUserDefaults;
#property (nonatomic,retain) NSUserDefaults *objUserDefaults;
.m file
#synthesize objUserDefaults;
Where you first time login Method write this on response\
objUserDefaults = [NSUserDefaults standardUserDefaults]
[objUserDefaults setObject:#"1" forKey:#"Login"];
and when you required for login check then
NSString *strSuccess=[objUserDefaults objectForKey:#"Login"];
if ([strSuccess isEqualToString:#"1"]) {
// just push the next view.
}
else {
// open login screen
}
OrganizationCode is not a string, and you are getting it as a string with this:
OrganizationCode = [[NSUserDefaults standardUserDefaults] stringForKey:#"OrganizationCode"];
You need to use objectForKey: instead, try with that:
OrganizationCode = [[NSUserDefaults standardUserDefaults] objectForKey:#"OrganizationCode"];
And another thing, OrganizationCode seems like the name of a class, not an instance of an object, are you sure you are using it in the right way?
To Store: Login Button:
-(IBAction)Login:(id)sender
{
if (success) {
NSUserDefaults *status=[NSUserDefaults standardUserDefaults];
[status setObject:#"LOGGING" forKey:#"STATUS"];
// GO TO NEXT FUNCTION ??
}
}
To Get:Validation Button:
-(void)load_view
{
NSUserDefaults *status=[NSUserDefaults standardUserDefaults];
NSString *status_str=[status objectForKey:#"STATUS"];
if ([status_str isEqualToString:#"LOGGING"]) {
// GO TO NEXT SUCCESS FUNCTION
}
else
{
// GO TO Login View
}
}

NSUserDefaults remember view

My App contains a couple of views, I would like to display a small setup when the app launches and the user didn't complete the wizard yet.
I know I can achieve this with NSUserDefaults, But I'm unsure how I can make it to display a specific view depending on the input string of the NSUserDefaults storage.
My AppDelegate.m:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSString *controllerName = [[NSUserDefaults standardUserDefaults] objectForKey:#"WIZARD_VIEW"];
if ([controllerName length]) {
Class controllerClass = NSClassFromString(controllerName);
UIViewController *controller = [[controllerClass alloc] init];
// Override point for customization after application launch.
return YES;
}
Then in the viewcontroller files I added the following code as suggestion from jfaller:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSUserDefaults* standard=[NSUserDefaults standardUserDefaults];
[standard registerDefaults: #{ #"WIZARD_VIEW" : [[self class]description]} ]; [[NSUserDefaults standardUserDefaults] synchronize];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
NSUserDefaults* standard=[NSUserDefaults standardUserDefaults];
[standard registerDefaults: #{ #"WIZARD_VIEW" : [[self class]description]} ];
[[NSUserDefaults standardUserDefaults] synchronize];
}
But how can I make this so it will display the specific view that has been selected in the setup?
Personally, I would do the following:
Every time a user goes to a new view in your wizard, record the UIViewController in the user defaults:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[NSUserDefaults standardUserDefaults] setObject:[[self class] description] forKey:WIZARD_VIEW];
[[NSUserDefault standardUserDefaults] synchronize];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:WIZARD_VIEW];
[[NSUserDefault standardUserDefaults] synchronize];
}
When the user restarts the app (hypothetically in the middle of the wizard), reload the view:
- (BOOL)application:(UIApplication *)application
willFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// etc.
NSString *controllerName = [[NSUserDefaults standardUserDefaults] objectForKey:WIZARD_VIEW];
if ([controllerName length]) {
Class controllerClass = NSClassFromString(controllerName);
NSViewController *controller = [[controllerClass alloc] init];
// push the controller, or whatever....
}
// etc.
}
Write the view you are on to NSUserDefaults as the view loads. Then check for the value in didFinishLaunchingWithOptions.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if ([[[NSUserDefaults standardUserDefaults] valueForKey:#"current_setup"] isEqualToString:#"1"]) {
//on view 1!
}
}

NSUserDefaults doubts in iphone SDK

I am integrating twitter in my app for sharing a text. My architecture of twitter integration is I have two Button _btnTwitter and _btntwitteLogout and when the user successfully login the twitter his name will display in _btntwitterLogout as title.
When the user tap the _btntwitterLogout it logs out the twitter and logout button hides and login button comes.every thing went ok.but when the user tap the login button(_btnTwitter) the Twitter login popup cmes for login purpose,here is the problem that am facing ,when the popup comes the user tap the cancel button of that popup the popup disappears and here the previous username of the user in the logout button.it didn't changes. I have put user defaults to check.
-(IBAction)_clickbtnTwitter:(id)sender
{
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:#"Twitter_logged"];
[_btntwitterLogeout setTitle:nil forState:UIControlStateNormal];
_btntwitterLogeout.hidden = NO;
_btnTwitter.hidden=YES;
if (_engine) return;
_engine = [[SA_OAuthTwitterEngine alloc] initOAuthWithDelegate: self];
_engine.consumerKey = kOAuthConsumerKey;
_engine.consumerSecret = kOAuthConsumerSecret;
UIViewController *controller = [SA_OAuthTwitterController controllerToEnterCredentialsWithTwitterEngine: _engine delegate: self];
if (controller)
[self presentModalViewController: controller animated: YES];
else {
[_engine sendUpdate: [NSString stringWithFormat: #"Already Updated. %#", [NSDate date]]];
}
}
}
then logout code
-(IBAction)_clickbtntwitterlogeout:(id)sender
{
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:#"Twitter_logged"];
crosstwitterimage.hidden = YES;
[_btntwitterLogeout setTitle:nil forState:UIControlStateNormal];
_btntwitterLogeout.hidden = YES;
_btnTwitter.hidden=NO;
_btnTwittermain.enabled = NO;
[_engine clearAccessToken];
[_engine clearsCookies];
[_engine setClearsCookies:YES];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:#"authData"];
[[NSUserDefaults standardUserDefaults]removeObjectForKey:#"authName"];
NSLog(#"%#",[[NSUserDefaults standardUserDefaults]valueForKey:#"authName"]);
NSLog(#"%#",[[NSUserDefaults standardUserDefaults]valueForKey:#"authData"]);
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:#"Twitter_logged"];
[_engine release];
_engine=nil;
NSHTTPCookie *cookie;
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (cookie in [storage cookies])
{
NSString* domainName = [cookie domain];
NSRange domainRange = [domainName rangeOfString:#"twitter"];
if(domainRange.length > 0)
{
[storage deleteCookie:cookie];
}
}
}
in viewwillappear
BOOL logged = [[NSUserDefaults standardUserDefaults] boolForKey:#"Twitter_logged"];
;
if (logged == YES) {
_btnTwitter. hidden = YES;
_btntwitterLogeout.hidden = NO;
crosstwitterimage.hidden = NO;
_btnTwittermain.enabled =YES;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
//Checks if there is a saved User Name
if([defaults objectForKey:#"kTwitterUserName"])
{
NSString *username = [defaults objectForKey:#"kTwitterUserName"];
[_btntwitterLogeout setTitle:username forState:UIControlStateNormal];
crosstwitterimage.hidden = NO;
}
}
else
{
_btnTwitter. hidden = NO;
crosstwitterimage.hidden = YES;
[_btntwitterLogeout setTitle:nil forState:UIControlStateNormal];
_btnTwittermain.enabled =NO;
crosstwitterimage.hidden = YES;
}
but when i tap the cancel button in loginwindow of twitter,an comes back the username with the logout button shows ,if the user is already logedout from twitter.
is there any problem in my code.
thanks in advance.
EDIT
#pragma mark SA_OAuthTwitterEngineDelegate
- (void) storeCachedTwitterOAuthData: (NSString *) data forUsername: (NSString *) username {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject: data forKey: #"authData"];
[defaults synchronize];
}
- (NSString *) cachedTwitterOAuthDataForUsername: (NSString *) username {
return [[NSUserDefaults standardUserDefaults] objectForKey: #"authData"];
}
#pragma mark SA_OAuthTwitterControllerDelegate
- (void) OAuthTwitterController: (SA_OAuthTwitterController *) controller authenticatedWithUsername: (NSString *) username {
NSLog(#"Authenicated for %#", username);
[_btntwitterLogeout setTitle:username forState:UIControlStateNormal];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:username forKey:#"kTwitterUserName"];
[defaults synchronize];
}
- (void) OAuthTwitterControllerFailed: (SA_OAuthTwitterController *) controller {
NSLog(#"Authentication Failed!");
}
- (void) OAuthTwitterControllerCanceled: (SA_OAuthTwitterController *) controller {
NSLog(#"Authentication Canceled.");
}
#pragma mark TwitterEngineDelegate
- (void) requestSucceeded: (NSString *) requestIdentifier {
NSLog(#"Request %# succeeded", requestIdentifier);
}
- (void) requestFailed: (NSString *) requestIdentifier withError: (NSError *) error {
NSLog(#"Request %# failed with error: %#", requestIdentifier, error);
}
Yes there is a problem. Whenever you hit the _btnTwitter, you are setting the Twitter_logged to yes. That's not correct. You should only set it to yes when there is a successful login. That is when the user has NOT hit cancel on the twitter login window.
In other words, you need to set the Twitter_logged to YES once the user has actually logged in, not when the user clicked on the button _btnTwitter
Seems like SA_OAuthTwitterController has a delegate property pointing to self. You should handle code to set Twitter_logged YES in that delegate method.
Hope that helps.
Edit:
Given the latest code here is where you should add the NsUserDefaults data
- (void) OAuthTwitterController: (SA_OAuthTwitterController *) controller authenticatedWithUsername: (NSString *) username {
NSLog(#"Authenicated for %#", username);
[_btntwitterLogeout setTitle:username forState:UIControlStateNormal];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:username forKey:#"kTwitterUserName"];
[defaults setBool:YES forKey:#"Twitter_logged"]; // Right here - mbh
[defaults synchronize];
}

fbconnect logout is not working perfectly

i have integrated Fbconnect in LoginViewController.I want to logout the session from another view controller .. How i can do this ?
I tried this ..
LoginViewController *obj1 = [[LoginViewController alloc] init];
[obj1._session logout];
[obj1._session.delegates removeObject: self];
It removing the session..But wen i go to LoginViewController the button is showing logout.But when i quit application and run it, the image is updated.
In LoginViewController i have
#interface LoginViewController : UIViewController <FBDialogDelegate, FBSessionDelegate, FBRequestDelegate>{
IBOutlet UITextField *txtUsername;
IBOutlet UITextField *txtPassword;
IBOutlet UILabel *lblMessage;
IBOutlet FBLoginButton* _loginButton;
FBSession* _session;
}
#property (nonatomic, retain) FBSession *_session;
and am synthesizing it #synthesize _session;
....What else i have to do ?
Somebody please help me..am very new to Iphone application and objective c
I got the answer ..My Friend helped me.. i want to share it...
simply
import "FBConnect.h"
in ur second view controller
then .......
FBSession *session = [FBSession
session]; [session logout];
It works fine
-(void)clickfb:(id)sender
{
NSHTTPCookieStorage* cookies = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (NSHTTPCookie* cookie in
[[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]) {
[cookies deleteCookie:cookie];
}
[self showLoggedOut:YES];
}
(void) showLoggedOut:(BOOL)clearInfo {
//[self.navigationController setNavigationBarHidden:YES animated:NO];
// // Remove saved authorization information if it exists and it is
// // ok to clear it (logout, session invalid, app unauthorized)
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if (clearInfo && [defaults objectForKey:#"FBAccessTokenKey"]) {
[defaults removeObjectForKey:#"FBAccessTokenKey"];
[defaults removeObjectForKey:#"FBExpirationDateKey"];
[defaults synchronize];
//
// // Nil out the session variables to prevent
// // the app from thinking there is a valid session
AppDelegate *delegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];
if (nil != [[delegate facebook] accessToken]) {
[delegate facebook].accessToken = nil;
}
if (nil != [[delegate facebook] expirationDate]) {
[delegate facebook].expirationDate = nil;
}
}
}