SwiftyInAppMessaging
与 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>()
}
依赖
- Firebase iOS SDK ==
10.0.0
安装
Carthage
只需添加您的 Cartfile
github "fumito-ito/SwiftyInAppMessaging" ~> 2.0.0
然后运行 carthage update
Swift 包管理器
只需将其添加到依赖项下的 Package.swift
let package = Package(
name: "MyPackage",
products: [...],
dependencies: [
.package(url: "https://github.com/fumito-ito/SwiftyInAppMessaging.git", .upToNextMajor(from: "2.0.0"))
]
)
Cocoapods
只需将其添加到您的 Podfile
pod 'SwiftyInAppMessaging'
然后运行 pod install
如果您收到关于 Double-quoted include "*.h" in framework header, expected angle-bracketed instead
的错误,可以按照以下步骤避免这些错误。
推荐
- 更新您到 Cocoapods
1.10
或更高版本 - 再次运行
pod install
如果您无法更新 Cocoapods
- 点击
Pods
项目 - 点击项目的
构建设置
- 将
框架头部的引号包含
改为否
有关更多信息,请参阅 一个 Firebase iOS SDK 问题。
许可协议
SwiftyInAppMessaging 根据 Apache License 2.0 提供。有关更多详细信息,请参阅 LICENSE 文件。