Rich Media แบบโมดอลสำหรับ iOS
ตั้งแต่ Pushwoosh SDK เวอร์ชัน 6.7.5 เป็นต้นไป คุณสามารถส่ง Modal Rich Media ได้
เรากำลังเปิดตัว Modal Rich Media ใหม่ซึ่งสามารถปรับแต่งได้ Modal Rich Media ใหม่นี้จะไม่บล็อกหน้าจอทั้งหมดและสามารถจัดตำแหน่งในส่วนต่างๆ ของหน้าจอได้ (ด้านบน ด้านล่าง และตรงกลาง)
สำหรับข้อมูลเพิ่มเติมเกี่ยวกับหน้า Rich Media โปรดดูที่ คู่มือของเรา
การกำหนดค่า
Anchor link to//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หากต้องการเปิดใช้งานการแสดง Modal Rich Media ให้ตั้งค่าพารามิเตอร์ Pushwoosh_RICH_MEDIA_STYLE ใน info.plist ของคุณและกำหนดค่าเป็น MODAL_RICH_MEDIA
Info.plist:
<key>Pushwoosh_RICH_MEDIA_STYLE</key><string>MODAL_RICH_MEDIA</string>ตัวเลือกที่ 2: การกำหนดค่าผ่านโปรแกรม (SDK 7.0.14+)
Anchor link toคุณยังสามารถกำหนดค่ารูปแบบการนำเสนอ Rich Media ผ่านโปรแกรมใน AppDelegate ของคุณได้:
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;}โดยค่าเริ่มต้น Modal Rich Media จะแสดงที่กึ่งกลางของหน้าจอพร้อมกับแอนิเมชันการปรากฏจากล่างขึ้นบน
การจัดตำแหน่ง Modal Rich Media
Anchor link toModal Rich Media สามารถจัดตำแหน่งในตำแหน่งต่างๆ บนหน้าจอได้
/** 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)};ตัวอย่างด้านล่างแสดง Modal Rich Media ที่แสดงที่ด้านบนของหน้าจอ
แอนิเมชันการแสดง Modal Rich Media ประกอบด้วย:
typedef NS_ENUM(NSInteger, PresentModalWindowAnimation) { PWAnimationPresentFromBottom, PWAnimationPresentFromTop, PWAnimationPresentFromRight, PWAnimationPresentFromLeft, PWAnimationPresentNone};แอนิเมชันการปิด Modal Rich Media ประกอบด้วย:
typedef NS_ENUM(NSInteger, DismissModalWindowAnimation) { PWAnimationDismissDown, PWAnimationDismissUp, PWAnimationDismissLeft, PWAnimationDismissRight, PWAnimationCurveEaseInOut, PWAnimationDismissNone,
/** * Default dismiss animation is `PWAnimationCurveEaseInOut` */ PWAnimationDismissDefault};ตัวอย่างด้านล่างสาธิตการแสดง Modal Rich Media ที่ด้านล่างของหน้าจอพร้อมแอนิเมชันการแสดงจากซ้ายไปขวาและแอนิเมชันการปิดไปทางขวา:
พารามิเตอร์เพิ่มเติมสำหรับ Modal Rich Media
Anchor link toพารามิเตอร์เพิ่มเติมสำหรับการแสดง Modal Rich Media รวมถึงตัวเลือกต่างๆ เช่น การเพิ่ม haptic feedback ประเภทการสั่น การเปิดใช้งาน swipe gestures และการตั้งเวลาปิดอัตโนมัติหลังจากระยะเวลาที่กำหนด
// 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];ประเภท Haptic Feedback:
typedef NS_ENUM(NSInteger, HapticFeedbackType) { PWHapticFeedbackLight, // Light vibration feedback PWHapticFeedbackMedium, // Medium vibration feedback PWHapticFeedbackHard, // Strong vibration feedback PWHapticFeedbackNone // Vibration is off (default)};ทิศทางการปัด (Swipe Directions):
typedef NS_ENUM(NSInteger, DismissSwipeDirection) { PWSwipeDismissDown, PWSwipeDismissUp, PWSwipeDismissLeft, PWSwipeDismissRight, PWSwipeDismissNone};PWRichMediaPresentingDelegate
Anchor link toในการจัดการคิวของ modal rich media คุณต้องติดตั้งเมธอด delegate ของ PWRichMediaPresentingDelegate
เมื่อใช้ฟังก์ชันนี้ modal rich media จะถูกนำเสนอตามลำดับ และอันถัดไปจะไม่แสดงจนกว่าผู้ใช้จะปิดอันปัจจุบัน เมื่อผู้ใช้ปิด rich media ที่นำเสนอแล้ว อันถัดไปซึ่งเป็นส่วนหนึ่งของการแจ้งเตือนแบบพุชอื่นจะปรากฏขึ้น
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