Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7560271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:51:25+00:00 2026-05-30T12:51:25+00:00

I think that my problem is not that hard to solve. I must be

  • 0

I think that my problem is not that hard to solve. I must be missing out on something. I let my users login with Facebook so in the Application settings I have an option to logout from Facebook with an on/off switch. My Root.plist in Settings.bundle looks like this:

<dict>
    <key>PreferenceSpecifiers</key>
    <array>
        <dict>
            <key>Title</key>
            <string></string>
            <key>Type</key>
            <string>PSGroupSpecifier</string>
        </dict>
        <dict>
            <key>DefaultValue</key>
            <false/>
            <key>Key</key>
            <string>facebookLogoutTriggered</string>
            <key>Title</key>
            <string>Logout Facebook</string>
            <key>Type</key>
            <string>PSToggleSwitchSpecifier</string>
        </dict>
    </array>
    <key>StringsTable</key>
    <string>Root</string>
</dict>

So basically the functionality I’m after is that if the user switches the switch to ON, he should be logged out from Facebook. After he has been logged out the switch should switched back to OFF. So I want OFF to be the default value of the switch.

Since booleans default to NO (OFF) I’m thinking I don’t need to use NSUserDefault´s registerDefaults:

So I check in applicationWillEnterForeground: if the user has turned the switch to on in App Settings by checking this:

// Check if the user wants to logout from Facebook
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
BOOL facebookLogoutTriggered = [defaults boolForKey:@"facebookLogoutTriggered"];

// Set "Logout Facebook" setting to OFF (NO)    
[defaults setBool:NO forKey:@"facebookLogoutTriggered"];
[defaults synchronize];

But for some reason this code doesn’t seem to work. Most of the time it works (swith is switched off after the check). But sometimes i.e after logging in to Facebook it will set the switch to on for some reason. The code I run after logging in to Facebook is this:

#pragma mark - FBSessionDelegate Methods

- (void)fbDidLogin {

    DLog(@"User logged in to Facebook.");

    AppDelegate *appDelegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];

    // Save accesstoken and expirationdate
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:[appDelegate.facebook accessToken] forKey:@"FBAccessTokenKey"];
    [defaults setObject:[appDelegate.facebook expirationDate] forKey:@"FBExpirationDateKey"];

    [defaults synchronize];

    DLog(@"defaults %@", [defaults objectForKey:@"facebookLogoutTriggered"]);

}

Been trying to fix this for 6 hours now but can’t really proceed any further.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T12:51:27+00:00Added an answer on May 30, 2026 at 12:51 pm

    For some reason, it seems that I have to do a [[NSUserDefaults standardUserDefaults] synchronize]; after the user has set an application setting. I only thought you had to call -synchronize directly after you are saving your values to NSUserDefaults but apparently it seems that you have to call it directly after retrieving your NSUserDefaults IF the user has set a preference in the Application settings (Settings.bundle).

    So instead of doing:

    // Check if the user wants to logout from Facebook
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    BOOL facebookLogoutTriggered = [defaults boolForKey:@"facebookLogoutTriggered"];
    
    // Set "Logout Facebook" setting to OFF (NO)    
    [defaults setBool:NO forKey:@"facebookLogoutTriggered"];
    [defaults synchronize];
    

    I now do:

    // Check if the user wants to logout from Facebook
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    // Make SURE we get the updated data from the Application Settings
    [defaults synchronize];
    BOOL facebookLogoutTriggered = [defaults boolForKey:@"facebookLogoutTriggered"];
    
    // Set "Logout Facebook" setting to OFF (NO)    
    [defaults setBool:NO forKey:@"facebookLogoutTriggered"];
    [defaults synchronize];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem drawing something quickly in .NET. I don't think that any
i have a problem that i can't solve ! (sqlite3, but i think it
I think that this problem can be sorted using reflection (a technology which I'm
I've got a pretty minor problem that I think can be resolved by re-thinking
I have a peculiar problem, which I think that a lot of other people
My problem is one that you would think is quite common, but I haven't
Here's a coding problem for those that like this kind of thing. Let's see
Recently I found out the hard way that to convert between LatLngs and pixel
I'm about to tackle what I see as a hard problem, I think. I
I thought long and hard and can't think of problems that cannot be solved

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.