انتقل إلى المحتوى

الوسائط الغنية المشروطة لنظام iOS

بدءًا من إصدار Pushwoosh SDK 6.7.5، لديك القدرة على إرسال الوسائط الغنية المشروطة (Modal Rich Media).

نحن نقدم وسائط غنية مشروطة (Modal Rich Media) جديدة يمكن تخصيصها. الوسائط الغنية المشروطة الجديدة لا تحجب الشاشة بالكامل ويمكن وضعها في أجزاء مختلفة من الشاشة (أعلى، أسفل، وفي المنتصف).

لمزيد من المعلومات حول صفحات الوسائط الغنية، يرجى الرجوع إلى دليلنا.

الإعدادات

Anchor link to
//for silent push notifications
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
Pushwoosh.configure.handlePushReceived(userInfo)
completionHandler(.noData)
}

الخيار 1: إعدادات Info.plist

Anchor link to

لتمكين عرض الوسائط الغنية المشروطة، قم بتعيين المعلمة 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

يمكنك أيضًا تكوين نمط عرض الوسائط الغنية برمجيًا في 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
}

بشكل افتراضي، سيتم عرض الوسائط الغنية المشروطة في منتصف الشاشة مع حركة ظهور من الأسفل إلى الأعلى.

تحديد موضع الوسائط الغنية المشروطة

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
Pushwoosh.media.modalRichMedia.setHapticFeedbackType(.PWHapticFeedbackLight)
// Swipe directions to dismiss
Pushwoosh.media.modalRichMedia.setDismissSwipeDirections([
NSNumber(value: DismissSwipeDirection.PWSwipeDismissDown.rawValue),
NSNumber(value: DismissSwipeDirection.PWSwipeDismissUp.rawValue)
])
// Set Rich Media corner radius
let topCorners = PWCornerTypeTopLeft.rawValue | PWCornerTypeTopRight.rawValue
Pushwoosh.media.modalRichMedia.setCornerType(CornerType(rawValue: topCorners), withRadius: 16)
// Close Modal Rich Media after N seconds
Pushwoosh.media.modalRichMedia.closeAfter(3)

أنواع ردود الفعل اللمسية:

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 to

لإدارة قائمة انتظار الوسائط الغنية المشروطة، تحتاج إلى تنفيذ أساليب المفوض (delegate) الخاصة بـ PWRichMediaPresentingDelegate. عند استخدام هذه الوظيفة، يتم تقديم الوسائط الغنية المشروطة بشكل تسلسلي، ولن يتم عرض الوسيط التالي حتى يغلق المستخدم الوسيط الحالي. بمجرد أن يغلق المستخدم الوسائط الغنية المعروضة، سيتم عرض الوسيط التالي، الذي كان جزءًا من إشعار دفع مختلف.

import UIKit
import PushwooshFramework
@main
class 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)
}
}