ข้ามไปยังเนื้อหา

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 notifications
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
Pushwoosh.sharedInstance().handlePushReceived(userInfo)
completionHandler(.noData)
}
  1. หากต้องการเปิดใช้งานการแสดง 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>
  1. โดยค่าเริ่มต้น Modal Rich Media จะแสดงที่กึ่งกลางของหน้าจอพร้อมกับแอนิเมชันการปรากฏตัวจากล่างขึ้นบน
  1. หากต้องการกำหนดค่าการแสดงผลของ Modal Rich Media (ตำแหน่งบนหน้าจอ แอนิเมชันการแสดง แอนิเมชันการปิด) คุณต้องใช้วิธีการต่อไปนี้:
// Modal Rich Media Configuration
PWModalWindowConfiguration.shared().configureModalWindow(with: .PWModalWindowPositionCenter,
present: .PWAnimationPresentFromBottom,
dismiss: .PWAnimationDismissUp)

การจัดตำแหน่ง Modal Rich Media

Anchor link to

Modal 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 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

ในการจัดการคิวของ modal rich media คุณต้องใช้วิธีการ delegate ของ PWRichMediaPresentingDelegate เมื่อใช้ฟังก์ชันนี้ modal rich media จะถูกนำเสนอตามลำดับ และอันถัดไปจะไม่แสดงจนกว่าผู้ใช้จะปิดอันปัจจุบัน เมื่อผู้ใช้ปิด rich media ที่นำเสนอแล้ว อันถัดไปซึ่งเป็นส่วนหนึ่งของการแจ้งเตือนแบบพุชอื่นจะปรากฏขึ้น

หากต้องการใช้ฟังก์ชันนี้ ให้ใช้โค้ดที่ให้ไว้ด้านล่าง:

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)
}
}