共存您的自定义视图和 InAppMessaging 默认视图的最简单方法。
只需一步即可开始使用 SwiftyInAppMessaging。
func application(_ application: UIApplication, didFinishLaunchWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
InAppMessaging.inAppMessaging().messageDisplayComponent = SwiftyInAppMessaging()
}
struct InAppMyModalMessageHandler: InAppModalMessageHandler {
let messageForDisplay: InAppMessagingModalDisplay
init(message messageForDisplay: InAppMessagingModalDisplay) {
self.messageForDisplay = messageForDisplay
}
func displayMessage(with delegate: InAppMessagingDisplayDelegate) throws {
let alert = UIAlertController(title: self.messageForDisplay.title)
let ok = UIAlertAction(title: "OK", style: .default, handler: { [weak self] _ in
guard let messageForDisplay = self?.messageForDisplay else {
return
}
delegate.messageClicked?(messageForDisplay, with: InAppMessagingAction(actionText: "OK", actionURL: nil)
})
alert.addAction(ok)
DispatchQueue.main.async {
UIApplication.shared.topViewController?.present(alert, animated: true, completion: nil)
}
}
func displayError(_ error: Error) {
debugLog(error)
}
}
enum YourOwnMessageRouter {
case banner(InAppMessagingBannerDisplay)
case card(InAppMessagingCardDisplay)
case customModal(InAppMessagingModalDisplay)
case imageOnly(InAppMessagingImageOnlyDisplay)
static func match(for message: InAppMessagingDisplayMessage) -> Self? {
switch message.typeWithDisplayMessage {
case .banner(let message):
return .banner(message: message)
case .card(let message):
return .card(message: message)
case .imageOnly(let message):
return .imageOnly(message: message)
case .modal(let message):
return .customModal(message: message)
@unknown default:
return nil
}
var messageHandler: InAppMessageHandler {
switch self {
case .banner(let message):
return message.defaultHandler
case .card(let message):
return message.defaultHandler
case .imageOnly(let message):
return message.defaultHandler
case .customModal(let message):
return InAppMyModalMessageHandler(message: message)
}
}
}
func application(_ application: UIApplication, didFinishLaunchWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
InAppMessaging.inAppMessaging().messageDisplayComponent = SwiftyInAppMessaging<YourOwnMessageRouter>()
}
11.0.0
只需添加到您的 Cartfile
github "fumito-ito/SwiftyInAppMessaging" ~> 2.0.0
并运行 carthage update
只需将其添加到您的 Package.swift
中的 dependencies 下
let package = Package(
name: "MyPackage",
products: [...],
dependencies: [
.package(url: "https://github.com/fumito-ito/SwiftyInAppMessaging.git", .upToNextMajor(from: "2.0.0"))
]
)
只需添加到您的 Podfile
pod 'SwiftyInAppMessaging'
并运行 pod install
如果您遇到关于 Double-quoted include "*.h" in framework header, expected angle-bracketed instead
的错误,您可以通过以下步骤避免这些错误。
1.10
或更高版本pod install
Pods
项目Build Settings
Quoted include in Framework Header
更改为 No
有关更多信息,请参阅 一个 firebase-ios-sdk 问题。
SwiftyInAppMessaging 根据 Apache License 2.0 许可。 有关更多详细信息,请参见 LICENSE 文件。