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

  • Home
  • SEARCH
  • 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 6535381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:22:01+00:00 2026-05-25T10:22:01+00:00

I have an iPad app where the user can set the idleTimerDisabled to YES

  • 0

I have an iPad app where the user can set the idleTimerDisabled to YES or NO via a switch in preferences. That part works fine. However, initially setting it to YES in the app delegate’s didFinishLaunchingWithOptions method if it’s the first time the app has run doesn’t work (the device auto-sleeps anyway).

I’ve tried the hack of setting it to NO first, then to YES, as described in other threads to no avail. All other aspects of the preferences (standardUserDefaults) are working fine, as well.

Here’s the relevant code:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
    // if app run for the first time, set these as defaults
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
    if (![prefs objectForKey:@"autoSleep"]) {
    // this conditional code runs, as traced using NSLog   
    [prefs setBool:YES forKey:@"autoSleep"];
    application.idleTimerDisabled = NO;
    application.idleTimerDisabled = YES;
    }
}
  • 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-25T10:22:01+00:00Added an answer on May 25, 2026 at 10:22 am

    Use the registerDefaults method of NSUserDefaults instead of testing if objectForKey is nil.

    See also details about this in the relevant Programming Guide. Once you have register default values using registerDefaults (in your case the value NO for your "autoSleep" key), you are ensured that you will have a value in this key, either the one set in the application’s settings by the user… or this default one if the user hasn’t set a value for it yet.

    Thus it should solve your problem as you will always have a value for your autoSleep key, either the default one or the user-provided one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UIViewController for an iPad app where the user can pick one
I have an iPad app that works both on and offline but when I
I have an iPad app that uses custom fonts though the UIAppFonts elements in
I have an iPad app that has a UITableViewController that implements the NSFetchedResultsControllerDelegate .
I have this iPad app using Storyboard. There are some file that are marked
I have an iPad app that I would like to make Universal, however this
I have an ipad app that when you are in landscape view, the view
We have a POS apartment leasing iPad app that is used to collect a
It is an iPad app based on SDK 3.2. I have a MainUIView, that
I have an iPad App that is 51.87MB in size. I am trying to

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.