2015-09-04 45 views
0
UIApplicationState *state = [application applicationState]; 
if(state == UIApplicationStateActive) 
{ 
    NSLog(@"Display UIAlert"); 
} 

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

我得到这两个警告。当我试图找出我的应用程序是否在后台时,我得到这两个警告

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')) 

我不明白是什么问题。我想知道,如果我的应用程序在后台/非活动或前景

回答

2

[application applicationState]返回一个值,而不是一个对象(或指向任何东西)。

尝试:

UIApplicationState state = [application applicationState]; 
3

UIApplicationState是一个typedef定义枚举,因此你不需要*

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

您可以通过以下步骤修复您的代码:

UIApplicationState state = [application applicationState]; 
0

UIApplicationState是一种原始数据类型是INT的typedef为32位和长64位。 UIApplicationState使用NSInteger的数据类型的枚举,并声明它无需使用指针*在你的发言。

相关问题