# 마이그레이션 가이드

### Android SDK 5에서 6으로 마이그레이션

1.  [공식 문서](https://developer.android.com/jetpack/androidx/migrate)에 따라 프로젝트를 AndroidX로 마이그레이션합니다.
2.  **Firebase Cloud Messaging**을 사용하는 경우 앱의 **build.gradle** 파일에 새 모듈을 추가합니다.

```groovy title="build.gradle"
implementation 'com.pushwoosh:pushwoosh-firebase:+'
```

**Amazon**을 사용하고 **Firebase**를 사용하지 않는 경우에는 변경 사항이 필요하지 않습니다.

### 이전 버전 Android SDK에서 마이그레이션

Pushwoosh 클래스 및 메서드의 대부분은 5.0 릴리스 이후 더 이상 사용되지 않으며 일부는 사라졌습니다. **PushManager**, **BasePushMessageReceiver**, **BaseRegistrationReceiver**, **SendPushTagsCallback**, **PushFragment** 및 **PushEventListener** 클래스는 여전히 `com.pushwoosh:pushwoosh-deprecated` 라이브러리의 일부로 사용할 수 있지만, 가능한 한 빨리 새 API로 마이그레이션하는 것이 좋습니다.

## PushManager

**PushManager**는 다양한 기능에 대한 여러 메서드로 구성되었습니다. 이러한 메서드는 이제 다음과 같이 다른 클래스 및 라이브러리로 분할되었습니다.
`com.pushwoosh:pushwoosh`: **Pushwoosh**, **PushwooshNotificationSettings**, **PushwooshInApp**.
`com.pushwoosh:pushwoosh-badge`: **PushwooshBadge**.
`com.pushwoosh:pushwoosh-location`: **PushwooshLocation**.
`com.pushwoosh:pushwoosh-beacon`: **PushwooshBeacon**.

## BaseRegistrationReceiver

**BaseRegistrationReceiver**는 푸시 등록 및 등록 취소 이벤트를 처리하는 데 사용되었습니다. 이 리시버는 이제 간단한 콜백 메커니즘으로 대체되었습니다.

```java
Pushwoosh.getInstance().registerForPushNotifications(result -> {
    if (result.isSuccess()) {
        String token = result.getData();
        // handle successful registration
    }
    else {
        PushwooshException exception = result.getException();
        // handle registration error
    }
});
```

## BasePushMessageReceiver

**BasePushMessageReceiver**는 포그라운드에서 푸시 알림을 수신할 때 iOS 알림 동작을 모방하는 데 사용되었습니다. 이는 수신 알림을 취소하고 **onMessageReceive** 콜백을 호출하여 달성되었습니다. 이는 번거로웠고 애플리케이션이 활성화될 때 수동 등록이 필요했으며 애플리케이션이 백그라운드로 전환될 때 등록 취소가 필요했습니다.
이 리시버는 **NotificationServiceExtension**으로 대체되었습니다.

```txt title="AndroidManifest.xml"
<meta-data
    android:name="com.pushwoosh.notification_service_extension"
    android:value="com.your.package.name.YourNotificationServiceExtension"/>
```

```java title="YourNotificationServiceExtension.java"
public class YourNotificationServiceExtension extends NotificationServiceExtension {
    @Override
    public boolean onMessageReceived(final PushMessage message) {
        if (isAppOnForeground()) {
            Handler mainHandler = new Handler(getApplicationContext().getMainLooper());
            mainHandler.post(() -> {
                handlePush(message);
            });

            // this indicates that notification should not be displayed
            return true;
        }

        return false;
    }

    @Override
    protected void startActivityForPushMessage(PushMessage message) {
        super.startActivityForPushMessage(message);
        handlePush(message);
    }

    @MainThread
    private void handlePush(PushMessage message) {
        // TODO: handle push message
    }
}
```

이 확장 기능은 알림 도착 및 수락 이벤트를 처리하는 데도 사용되므로 수동 Activity 통합에 사용되었던 모든 번거로운 코드를 대체합니다.

## PushFragment

**PushFragment**는 Activity 라이프사이클을 포함하는 복잡한 통합에 대한 경량 대안이었습니다. 그러나 다른 한편으로는 **FragmentActivity** 상속이 필요했고 암시적으로 더 복잡한 Fragment 라이프사이클을 사용했습니다.
**PushFragment** 및 **PushEventListener**는 이제 **Pushwoosh#registerForPushNotifications(Callback)** 및 **NotificationServiceExtension**으로 대체되었습니다.

## 사용자 지정 푸시 브로드캐스트 리시버 (PW_NOTIFICATION_RECEIVER)

**PW_NOTIFICATION_RECEIVER**는 사용자가 알림을 클릭할 때 동작을 사용자 지정하는 데 사용되었습니다. 이를 통해 Activity 컨텍스트 외부에서 알림을 처리하고 알림 내용에 따라 다른 Activity를 열 수 있었습니다. 이 통합은 더 이상 존재하지 않는 내부 Pushwoosh SDK API를 사용했습니다.
이 리시버는 이제 **NotificationServiceExtension**으로 완전히 대체되었습니다.

```java title="YourNotificationServiceExtension.java"
public class YourNotificationServiceExtension extends NotificationServiceExtension {
    @Override
    protected void startActivityForPushMessage(PushMessage message) {
    	// super.startActivityForPushMessage() starts default launcher activity 
    	// or activity marked with ${applicationId}.MESSAGE action.
    	// Simply do not call it to override this behaviour.
        // super.startActivityForPushMessage(message);

        // start your activity instead:
        Intent launchIntent  = new Intent(getApplicationContext(), YourActivity.class);             
        launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
 
        // (Optional) pass notification data to Activity
        launchIntent.putExtra(Pushwoosh.PUSH_RECEIVE_EVENT, message.toJson().toString());
 
        context.startActivity(launchIntent);
    }
}
```

## 알림 팩토리

알림 팩토리와 관련된 몇 가지 주요 변경 사항도 있었습니다.

**1.** **AbsNotificationFactory**는 **NotificationFactory**로 대체되었습니다.
**2.** **AbsNotificationFactory#onPushReceived(PushData)** 및 **AbsNotificationFactory#onPushHandle(Activity)** 메서드는 **NotificationServiceExtension** 클래스 (**onMessageReceived**, **startActivityForPushMessage**)로 대체되었습니다.
**3.** **DefaultNotificationFactory**는 **PushwooshNotificationFactory**로 대체되었습니다.
**4.** **PushData**는 **PushMessage**로 대체되었습니다.

## 인앱 메시지

**1.** **InAppFacade**는 **PushwooshInApp**으로 대체되었습니다.
**2.** 다음 API를 포함하는 JavaScript 네이티브 인터페이스를 위해 `pushwoosh` 객체가 도입되었습니다.
**getHwid(): string** - 현재 장치의 pushwoosh hwid를 반환합니다.
**getVersion(): string** - 현재 pushwoosh SDK 버전을 반환합니다.
**postEvent(event: string, attributes?: object, successCallback?: function, errorCallback?: function)** - postEvent 요청을 보냅니다.
**sendTags(tags: object)** - 현재 장치와 연결된 태그를 보냅니다.
**getTags(successCallback: function, errorCallback?: function)** - 현재 장치와 연결된 태그를 반환합니다.
**closeInApp()** - 인앱 HTML 페이지를 닫습니다.

## 피드백을 공유해 주세요

귀하의 피드백은 더 나은 경험을 만드는 데 도움이 되므로, SDK 통합 과정에서 문제가 발생하면 언제든지 의견을 듣고 싶습니다. 어려움에 직면하더라도 [이 양식](https://docs.google.com/forms/d/e/1FAIpQLSd_0b8jwn-V_JmoPLIxIFYbHACCQhrzidOZV3ELywoQPXRSxw/viewform)을 통해 의견을 공유하는 것을 주저하지 마십시오.