GettingStarted
GettingStarted

Reputation: 7625

I am getting these two warnings when trying to find out if my application is in the background

UIApplicationState *state = [application applicationState];
if(state == UIApplicationStateActive)
{
    NSLog(@"Display UIAlert");
}

if((state == UIApplicationStateBackground)||(state == UIApplicationStateInactive))
{
   NSLog(@"App is in background");
}

I get these two warnings.

Incompatible integer to pointer conversion initializing 'UIApplicationState *' (aka 'enum UIApplicationState *') with an expression of type 'UIApplicationState' (aka 'enum UIApplicationState')

Comparison between pointer and integer ('UIApplicationState *' (aka 'enum UIApplicationState *') and 'NSInteger' (aka 'long'))

I don't understand what the issue is. I want to know if my app is in the background/inactive or foreground

Upvotes: 0

Views: 90

Answers (3)

Abhishek Bhardwaj
Abhishek Bhardwaj

Reputation: 98

UIApplicationState is a primitive datatype and is typedef of int for 32 bit and long for 64 bit. UIApplicationState uses the Enum of NSInteger Datatype and to declare it no need to use pointer* in your statement.

Upvotes: 0

danielrsmith
danielrsmith

Reputation: 4060

UIApplicationState is a typedef'd enum, therefore you do not need the *.

typedef enum : NSInteger {
   UIApplicationStateActive,
   UIApplicationStateInactive,
   UIApplicationStateBackground 
} UIApplicationState;

You can fix your code by doing the following:

UIApplicationState state = [application applicationState];

Upvotes: 3

Phillip Mills
Phillip Mills

Reputation: 31026

[application applicationState] returns a value, not an object (or a pointer to anything).

Try:

UIApplicationState state = [application applicationState];

Upvotes: 2

Related Questions