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'))
我不明白这个问题是什么。我想知道我的应用程序是在后台/不活动还是前台
答案 0 :(得分:3)
UIApplicationState
是一个typedef枚举,因此您不需要*
。
typedef enum : NSInteger {
UIApplicationStateActive,
UIApplicationStateInactive,
UIApplicationStateBackground
} UIApplicationState;
您可以通过执行以下操作来修复代码:
UIApplicationState state = [application applicationState];
答案 1 :(得分:2)
[application applicationState]
返回一个值,而不是一个对象(或指向任何东西的指针)。
尝试:
UIApplicationState state = [application applicationState];
答案 2 :(得分:0)
UIApplicationState是一种原始数据类型,对于32位是int的typedef而对于64位是long。 UIApplicationState使用NSInteger数据类型的枚举,并声明它不需要在语句中使用指针*。