3

I'm trying to check the application state of my iOS app, but when I check

[UIApplication sharedApplication].applicationState

I'm getting nil. I checked that [UIApplication sharedApplication] is not nil. I'm basically just checking whether or not the screen is on, so I'm just checking the result of the following:

[UIApplication sharedApplication].applicationState == UIApplicationStateActive

Any idea why I'm getting nil returned?

nevan king
  • 112,709
  • 45
  • 203
  • 241
ferson2020
  • 3,015
  • 3
  • 18
  • 26
  • `UIApplicationState` is an `enum` so `nil` doesn't make sense. – trojanfoe Feb 22 '13 at 16:06
  • 1
    Perhaps you are confusing `UIApplicationStateActive` (value `0`) with `nil`? – trojanfoe Feb 22 '13 at 16:09
  • @trojanfoe I'm debugging and after the line 'UIApplicationState *applicationState = [UIApplication sharedApplication].applicationState;' I query 'po applicationState' and get '$4 = 0x00000000 ' – ferson2020 Feb 22 '13 at 16:10
  • `UIApplicationState` is not a class; it's an enum. `UIApplicationStateActive` == 0, so that makes sense. – Alex Feb 22 '13 at 16:15

1 Answers1

3

OK your code is incorrect (I'm surprised it compiled):

UIApplicationState *applicationState = [UIApplication sharedApplication].applicationState;

Should be:

UIApplicationState applicationState = [UIApplication sharedApplication].applicationState;

(it's an enum not an object).

trojanfoe
  • 120,358
  • 21
  • 212
  • 242