콘텐츠로 건너뛰기

iOS 모달 리치 미디어

Pushwoosh SDK 버전 6.7.5 부터 모달 리치 미디어를 전송할 수 있습니다.

사용자 정의가 가능한 새로운 모달 리치 미디어를 소개합니다. 새로운 모달 리치 미디어는 화면을 완전히 가리지 않으며 화면의 여러 부분(상단, 하단, 중앙)에 배치할 수 있습니다.

리치 미디어 페이지에 대한 자세한 내용은 가이드를 참조하세요.

//for silent push notifications
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
Pushwoosh.sharedInstance().handlePushReceived(userInfo)
completionHandler(.noData)
}
  1. 모달 리치 미디어 표시를 활성화하려면 info.plist 에서 Pushwoosh_RICH_MEDIA_STYLE 파라미터를 설정하고 MODAL_RICH_MEDIA 값을 할당하세요.

Info.plist:

<key>Pushwoosh_RICH_MEDIA_STYLE</key>
<string>MODAL_RICH_MEDIA</string>
  1. 기본적으로 모달 리치 미디어는 화면 중앙에 아래에서 위로 나타나는 애니메이션과 함께 표시됩니다.
  1. 모달 리치 미디어의 표시(화면 위치, 표시 애니메이션, 닫기 애니메이션)를 구성하려면 다음 메서드를 사용해야 합니다:
// Modal Rich Media Configuration
PWModalWindowConfiguration.shared().configureModalWindow(with: .PWModalWindowPositionCenter,
present: .PWAnimationPresentFromBottom,
dismiss: .PWAnimationDismissUp)

모달 리치 미디어 위치 지정

Anchor link to

모달 리치 미디어는 상단, 하단, 중앙 세 곳에 위치할 수 있습니다.

/**
Enum defining the possible positions for displaying a modal window.
- `PWModalWindowPositionTop`: The modal window appears at the top of the screen, within the safe area.
- `PWModalWindowPositionCenter`: The modal window appears at the center of the screen, within the safe area.
- `PWModalWindowPositionBottom`: The modal window appears at the bottom of the screen, within the safe area.
- `PWModalWindowPositionBottomSheet`: The modal window appears at the very bottom of the screen, ignoring the safe area.
- `PWModalWindowPositionDefault`: The default position is the center of the screen, within the safe area.
*/
typedef NS_ENUM(NSInteger, ModalWindowPosition) {
PWModalWindowPositionTop, // Appears at the top of the screen (within safe area)
PWModalWindowPositionCenter, // Appears at the center of the screen (within safe area)
PWModalWindowPositionBottom, // Appears at the bottom of the screen (within safe area)
PWModalWindowPositionBottomSheet, // Appears at the very bottom of the screen (ignores safe area)
PWModalWindowPositionFullScreen, // Fullscreen, ignores safe area insets
PWModalWindowPositionDefault // Default position (center of the screen, within safe area)
};

아래 예시는 화면 상단에 표시되는 모달 리치 미디어를 보여줍니다.

모달 리치 미디어 표시 애니메이션은 다음과 같습니다:

typedef NS_ENUM(NSInteger, PresentModalWindowAnimation) {
PWAnimationPresentFromBottom,
PWAnimationPresentFromTop,
PWAnimationPresentFromRight,
PWAnimationPresentFromLeft,
PWAnimationPresentNone
};

모달 리치 미디어 닫기 애니메이션은 다음과 같습니다:

typedef NS_ENUM(NSInteger, DismissModalWindowAnimation) {
PWAnimationDismissDown,
PWAnimationDismissUp,
PWAnimationDismissLeft,
PWAnimationDismissRight,
PWAnimationCurveEaseInOut,
PWAnimationDismissNone,
/**
* Default dismiss animation is `PWAnimationCurveEaseInOut`
*/
PWAnimationDismissDefault
};

아래 예시는 화면 하단에 왼쪽에서 오른쪽으로 나타나는 애니메이션과 오른쪽으로 닫히는 애니메이션을 가진 모달 리치 미디어를 보여줍니다:

모달 리치 미디어의 추가 파라미터

Anchor link to

모달 리치 미디어 표시를 위한 추가 파라미터에는 진동 타입의 햅틱 피드백 추가, 스와이프 제스처 활성화, 지정된 시간 후 자동 닫기 타이머 설정과 같은 옵션이 포함됩니다.

// Haptic Feedback Type
PWModalWindowConfiguration.shared().setPresent(.PWHapticFeedbackLight)
/**
enum HapticFeedbackType
typedef NS_ENUM(NSInteger, HapticFeedbackType) {
PWHapticFeedbackLight, // Light vibration feedback
PWHapticFeedbackMedium, // Medium vibration feedback
PWHapticFeedbackHard, // Strong vibration feedback
/**
* Vibration is off by default.
*/
PWHapticFeedbackNone
};
*/
// Swipe directions
let directions: [NSNumber] = [
NSNumber(value: DismissSwipeDirection.PWSwipeDismissDown.rawValue),
NSNumber(value: DismissSwipeDirection.PWSwipeDismissUp.rawValue)
]
PWModalWindowConfiguration.shared().setDismissSwipeDirections(directions)
/**
typedef NS_ENUM(NSInteger, DismissSwipeDirection) {
PWSwipeDismissDown,
PWSwipeDismissUp,
PWSwipeDismissLeft,
PWSwipeDismissRight,
PWSwipeDismissNone
};
*/
// Set Rich Media corner radius
PWModalWindowConfiguration.shared().setCornerType([.PWCornerTypeTopLeft, .PWCornerTypeBottomRight], withRadius: 30.0)
// Close Modal Rich Media after N seconds
PWModalWindowConfiguration.shared().closeModalWindow(after: 3)

PWRichMediaPresentingDelegate

Anchor link to

모달 리치 미디어의 큐를 관리하려면 PWRichMediaPresentingDelegate의 델리게이트 메서드를 구현해야 합니다. 이 기능을 사용하면 모달 리치 미디어가 순차적으로 표시되며, 사용자가 현재 미디어를 닫을 때까지 다음 미디어가 표시되지 않습니다. 사용자가 표시된 리치 미디어를 닫으면 다른 푸시 알림의 일부였던 다음 리치 미디어가 표시됩니다.

이 기능을 구현하려면 아래 제공된 코드를 사용하세요:

import UIKit
import PushwooshFramework
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
PWRichMediaManager.shared().delegate = ChainedRichMediaPresentingDelegate.init(queue: [], inApp: false)
}
}
class ChainedRichMediaPresentingDelegate: NSObject, PWRichMediaPresentingDelegate {
var queue: [PWRichMedia]
var inAppIsPresenting: Bool
init(queue: [PWRichMedia], inApp: Bool) {
self.queue = queue
self.inAppIsPresenting = inApp
super.init() // can actually be omitted in this example because will happen automatically.
}
convenience override init() {
self.init(queue: [], inApp: false)
}
func richMediaManager(_ richMediaManager: PWRichMediaManager!, shouldPresent richMedia: PWRichMedia!) -> Bool {
if !queue.contains(where: { $0 === richMedia }) {
queue.append(richMedia)
}
return !inAppIsPresenting
}
func richMediaManager(_ richMediaManager: PWRichMediaManager!, didPresent richMedia: PWRichMedia!) {
inAppIsPresenting = true
}
func richMediaManager(_ richMediaManager: PWRichMediaManager!, didClose richMedia: PWRichMedia!) {
inAppIsPresenting = false
if let idx = queue.firstIndex(where: { $0 === richMedia }) {
queue.remove(at: idx)
}
if ((queue.count) != 0) {
PWModalWindowConfiguration.shared().presentModalWindow(queue.first!)
}
}
func richMediaManager(_ richMediaManager: PWRichMediaManager!, presentingDidFailFor richMedia: PWRichMedia!, withError error: Error!) {
self.richMediaManager(richMediaManager, didClose: richMedia)
}
}