Modale Rich Media für iOS
Ab der Pushwoosh SDK-Version 6.7.5 haben Sie die Möglichkeit, modale Rich Media zu senden.
Wir führen neue modale Rich Media ein, die individuell angepasst werden können. Die neuen modalen Rich Media blockieren den Bildschirm nicht vollständig und können an verschiedenen Stellen des Bildschirms positioniert werden (oben, unten und in der Mitte).
Weitere Informationen zu Rich-Media-Seiten finden Sie in unserem Leitfaden.
Konfiguration
Anchor link to//for silent push notificationsfunc application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { Pushwoosh.sharedInstance().handlePushReceived(userInfo) completionHandler(.noData)}- Um die Anzeige von modalen Rich Media zu aktivieren, setzen Sie den Parameter
Pushwoosh_RICH_MEDIA_STYLEin Ihrer info.plist und weisen Sie ihm den WertMODAL_RICH_MEDIAzu.
Info.plist:
<key>Pushwoosh_RICH_MEDIA_STYLE</key><string>MODAL_RICH_MEDIA</string>- Standardmäßig werden modale Rich Media in der Mitte des Bildschirms mit einer Erscheinungsanimation von unten nach oben angezeigt.
- Um die Anzeige von modalen Rich Media zu konfigurieren (Bildschirmposition, Einblendanimation, Schließanimation), müssen Sie die folgende Methode verwenden:
// Modal Rich Media ConfigurationPWModalWindowConfiguration.shared().configureModalWindow(with: .PWModalWindowPositionCenter, present: .PWAnimationPresentFromBottom, dismiss: .PWAnimationDismissUp)Positionierung von modalen Rich Media
Anchor link toModale Rich Media können an drei Positionen platziert werden: oben, unten oder in der Mitte.
/** 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)};Das folgende Beispiel zeigt eine modale Rich Media, die am oberen Rand des Bildschirms angezeigt wird.
Die Einblendanimationen für modale Rich Media umfassen:
typedef NS_ENUM(NSInteger, PresentModalWindowAnimation) { PWAnimationPresentFromBottom, PWAnimationPresentFromTop, PWAnimationPresentFromRight, PWAnimationPresentFromLeft, PWAnimationPresentNone};Die Schließanimationen für modale Rich Media umfassen:
typedef NS_ENUM(NSInteger, DismissModalWindowAnimation) { PWAnimationDismissDown, PWAnimationDismissUp, PWAnimationDismissLeft, PWAnimationDismissRight, PWAnimationCurveEaseInOut, PWAnimationDismissNone,
/** * Default dismiss animation is `PWAnimationCurveEaseInOut` */ PWAnimationDismissDefault};Das folgende Beispiel zeigt die Anzeige einer modalen Rich Media am unteren Bildschirmrand mit einer Einblendanimation von links nach rechts und einer Schließanimation nach rechts:
Zusätzliche Parameter für modale Rich Media
Anchor link toZusätzliche Parameter für die Anzeige von modalen Rich Media umfassen Optionen wie das Hinzufügen von haptischem Feedback (Vibration), die Aktivierung von Wischgesten und das Einstellen eines Timers zum automatischen Schließen nach einer festgelegten Dauer.
// Haptic Feedback TypePWModalWindowConfiguration.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 directionslet 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 radiusPWModalWindowConfiguration.shared().setCornerType([.PWCornerTypeTopLeft, .PWCornerTypeBottomRight], withRadius: 30.0)
// Close Modal Rich Media after N secondsPWModalWindowConfiguration.shared().closeModalWindow(after: 3)PWRichMediaPresentingDelegate
Anchor link toUm die Warteschlange der modalen Rich Media zu verwalten, müssen Sie die Delegate-Methoden von PWRichMediaPresentingDelegate implementieren. Bei Verwendung dieser Funktionalität werden modale Rich Media nacheinander präsentiert, und die nächste wird erst angezeigt, wenn der Benutzer die aktuelle schließt. Sobald der Benutzer die präsentierte Rich Media schließt, wird die nächste, die Teil einer anderen Push-Benachrichtigung war, angezeigt.
Um diese Funktionalität zu implementieren, verwenden Sie den unten stehenden Code:
import UIKitimport 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) }}