iOS Push 수신할 때 앱의 3가지 상태 확인


iOS 모바일 앱에서 Push를 수신할 때, 앱의 상태는 다음의 세 가지가 있습니다.


1. Push로 앱이 실행된 상태. (백그라운드가 아니라 킬 된 상태)

2. 앱이 포그라운드 실행 중인 상태.

3. 앱이 백그라운드 실행 중인 상태.


각각의 상태에서 별도의 다른 동작을 위해 이 상태를 구분할 필요가 있습니다.

AppDelegate 내에서 다음의 코드를 통해 구분이 가능합니다.


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

 

if (launchOptions && [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]) {

// 1번 상태에서 push 수신

}

 

return YES;

}

 

 

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo

{

if (application.applicationState == UIApplicationStateActive) {

// 2번 상태에서 push 수신

}

else {

// 3번 상태에서 push 수신

}

}