当我试图查明我的应用程序是否在后台时,我收到了这两个警告
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");
}
我收到这两个警告。
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'))
我不明白这是什么问题。我想知道我的应用程序是在 background/inactive 还是前台
[application applicationState]
returns 一个值,而不是一个对象(或指向任何东西的指针)。
尝试:
UIApplicationState state = [application applicationState];
UIApplicationState
是一个类型定义的枚举,因此您不需要 *
.
typedef enum : NSInteger {
UIApplicationStateActive,
UIApplicationStateInactive,
UIApplicationStateBackground
} UIApplicationState;
您可以通过执行以下操作来修复您的代码:
UIApplicationState state = [application applicationState];
UIApplicationState 是一种原始数据类型,32 位类型定义为 int,64 位类型定义为 long。 UIApplicationState 使用 NSInteger 数据类型的枚举,声明它不需要在你的语句中使用指针*。
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'))
我不明白这是什么问题。我想知道我的应用程序是在 background/inactive 还是前台
[application applicationState]
returns 一个值,而不是一个对象(或指向任何东西的指针)。
尝试:
UIApplicationState state = [application applicationState];
UIApplicationState
是一个类型定义的枚举,因此您不需要 *
.
typedef enum : NSInteger {
UIApplicationStateActive,
UIApplicationStateInactive,
UIApplicationStateBackground
} UIApplicationState;
您可以通过执行以下操作来修复您的代码:
UIApplicationState state = [application applicationState];
UIApplicationState 是一种原始数据类型,32 位类型定义为 int,64 位类型定义为 long。 UIApplicationState 使用 NSInteger 数据类型的枚举,声明它不需要在你的语句中使用指针*。