2015-09-04 46 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的數據類型的枚舉,並聲明它無需使用指針*在你的發言。

相關問題