iOS 모달 리치 미디어
Pushwoosh SDK 버전 6.7.5부터 **모달 리치 미디어(Modal Rich Media)**를 보낼 수 있습니다.
사용자 정의가 가능한 새로운 모달 리치 미디어를 소개합니다. 새로운 모달 리치 미디어는 화면을 완전히 가리지 않으며 화면의 다른 부분(상단, 하단, 중앙)에 배치할 수 있습니다.
리치 미디어 페이지에 대한 자세한 내용은 가이드를 참조하십시오.
//for silent push notificationsfunc application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { Pushwoosh.configure.handlePushReceived(userInfo) completionHandler(.noData)}옵션 1: Info.plist 구성
Anchor link to모달 리치 미디어 표시를 활성화하려면 info.plist에서 Pushwoosh_RICH_MEDIA_STYLE 매개변수를 설정하고 MODAL_RICH_MEDIA 값을 할당하십시오.
Info.plist:
<key>Pushwoosh_RICH_MEDIA_STYLE</key><string>MODAL_RICH_MEDIA</string>옵션 2: 프로그래밍 방식 구성 (SDK 7.0.14 이상)
Anchor link toAppDelegate에서 프로그래밍 방식으로 리치 미디어 표시 스타일을 구성할 수도 있습니다:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Set modal presentation style Pushwoosh.media.setRichMediaPresentationStyle(.modal)
// Configure modal window appearance Pushwoosh.media.modalRichMedia.configure( position: .PWModalWindowPositionBottom, presentAnimation: .PWAnimationPresentFromBottom, dismissAnimation: .PWAnimationDismissDown )
Pushwoosh.configure.registerForPushNotifications() return true}- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Set modal presentation style [[Pushwoosh media] setRichMediaPresentationStyle:PWRichMediaPresentationStyleModal];
// Configure modal window appearance [[[Pushwoosh media] modalRichMedia] configureWithPosition:PWModalWindowPositionBottom presentAnimation:PWAnimationPresentFromBottom dismissAnimation:PWAnimationDismissDown];
[[Pushwoosh configure] registerForPushNotifications]; return YES;}기본적으로 모달 리치 미디어는 화면 중앙에 아래에서 위로 나타나는 애니메이션과 함께 표시됩니다.
모달 리치 미디어 위치 지정
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 TypePushwoosh.media.modalRichMedia.setHapticFeedbackType(.PWHapticFeedbackLight)
// Swipe directions to dismissPushwoosh.media.modalRichMedia.setDismissSwipeDirections([ NSNumber(value: DismissSwipeDirection.PWSwipeDismissDown.rawValue), NSNumber(value: DismissSwipeDirection.PWSwipeDismissUp.rawValue)])
// Set Rich Media corner radiuslet topCorners = PWCornerTypeTopLeft.rawValue | PWCornerTypeTopRight.rawValuePushwoosh.media.modalRichMedia.setCornerType(CornerType(rawValue: topCorners), withRadius: 16)
// Close Modal Rich Media after N secondsPushwoosh.media.modalRichMedia.closeAfter(3)// Haptic Feedback Type[[[Pushwoosh media] modalRichMedia] setHapticFeedbackType:PWHapticFeedbackLight];
// Swipe directions to dismiss[[[Pushwoosh media] modalRichMedia] setDismissSwipeDirections:@[ @(PWSwipeDismissDown), @(PWSwipeDismissUp)]];
// Set Rich Media corner radiusCornerType topCorners = PWCornerTypeTopLeft | PWCornerTypeTopRight;[[[Pushwoosh media] modalRichMedia] setCornerType:topCorners withRadius:16.0];
// Close Modal Rich Media after N seconds[[[Pushwoosh media] modalRichMedia] closeAfter:3.0];햅틱 피드백 유형:
typedef NS_ENUM(NSInteger, HapticFeedbackType) { PWHapticFeedbackLight, // Light vibration feedback PWHapticFeedbackMedium, // Medium vibration feedback PWHapticFeedbackHard, // Strong vibration feedback PWHapticFeedbackNone // Vibration is off (default)};스와이프 방향:
typedef NS_ENUM(NSInteger, DismissSwipeDirection) { PWSwipeDismissDown, PWSwipeDismissUp, PWSwipeDismissLeft, PWSwipeDismissRight, PWSwipeDismissNone};PWRichMediaPresentingDelegate
Anchor link toPWRichMediaPresentingDelegate의 델리게이트 메서드를 구현하여 모달 리치 미디어의 큐를 관리해야 합니다. 이 기능을 사용하면 모달 리치 미디어가 순차적으로 표시되며, 사용자가 현재 미디어를 닫을 때까지 다음 미디어가 표시되지 않습니다. 사용자가 표시된 리치 미디어를 닫으면 다른 푸시 알림의 일부였던 다음 리치 미디어가 표시됩니다.
import UIKitimport PushwooshFramework
@mainclass AppDelegate: UIResponder, UIApplicationDelegate, PWRichMediaPresentingDelegate {
var richMediaQueue: [PWRichMedia] = [] var isPresenting = false
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Configure modal rich media Pushwoosh.media.setRichMediaPresentationStyle(.modal) Pushwoosh.media.modalRichMedia.configure( position: .PWModalWindowPositionBottom, presentAnimation: .PWAnimationPresentFromBottom, dismissAnimation: .PWAnimationDismissDown )
// Set delegate Pushwoosh.media.modalRichMedia.delegate = self
Pushwoosh.configure.registerForPushNotifications() return true }
// MARK: - PWRichMediaPresentingDelegate
func richMediaManager(_ richMediaManager: PWRichMediaManager, shouldPresent richMedia: PWRichMedia) -> Bool { if !richMediaQueue.contains(where: { $0 === richMedia }) { richMediaQueue.append(richMedia) } return !isPresenting }
func richMediaManager(_ richMediaManager: PWRichMediaManager, didPresent richMedia: PWRichMedia) { isPresenting = true }
func richMediaManager(_ richMediaManager: PWRichMediaManager, didClose richMedia: PWRichMedia) { isPresenting = false
if let idx = richMediaQueue.firstIndex(where: { $0 === richMedia }) { richMediaQueue.remove(at: idx) }
// Present next rich media in queue if let nextRichMedia = richMediaQueue.first { Pushwoosh.media.modalRichMedia.present(nextRichMedia) } }
func richMediaManager(_ richMediaManager: PWRichMediaManager, presentingDidFailFor richMedia: PWRichMedia, withError error: Error) { richMediaManager(richMediaManager, didClose: richMedia) }}#import "AppDelegate.h"#import <PushwooshFramework/PushwooshFramework.h>
@interface AppDelegate () <PWRichMediaPresentingDelegate>
@property (nonatomic, strong) NSMutableArray<PWRichMedia *> *richMediaQueue;@property (nonatomic, assign) BOOL isPresenting;
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.richMediaQueue = [NSMutableArray array]; self.isPresenting = NO;
// Configure modal rich media [[Pushwoosh media] setRichMediaPresentationStyle:PWRichMediaPresentationStyleModal]; [[[Pushwoosh media] modalRichMedia] configureWithPosition:PWModalWindowPositionBottom presentAnimation:PWAnimationPresentFromBottom dismissAnimation:PWAnimationDismissDown];
// Set delegate [[[Pushwoosh media] modalRichMedia] setDelegate:self];
[[Pushwoosh configure] registerForPushNotifications]; return YES;}
#pragma mark - PWRichMediaPresentingDelegate
- (BOOL)richMediaManager:(PWRichMediaManager *)richMediaManager shouldPresentRichMedia:(PWRichMedia *)richMedia { if (![self.richMediaQueue containsObject:richMedia]) { [self.richMediaQueue addObject:richMedia]; } return !self.isPresenting;}
- (void)richMediaManager:(PWRichMediaManager *)richMediaManager didPresentRichMedia:(PWRichMedia *)richMedia { self.isPresenting = YES;}
- (void)richMediaManager:(PWRichMediaManager *)richMediaManager didCloseRichMedia:(PWRichMedia *)richMedia { self.isPresenting = NO;
[self.richMediaQueue removeObject:richMedia];
// Present next rich media in queue if (self.richMediaQueue.count > 0) { [[[Pushwoosh media] modalRichMedia] presentRichMedia:self.richMediaQueue.firstObject]; }}
- (void)richMediaManager:(PWRichMediaManager *)richMediaManager presentingDidFailForRichMedia:(PWRichMedia *)richMedia withError:(NSError *)error { [self richMediaManager:richMediaManager didCloseRichMedia:richMedia];}
@end