The easiest way to coexist your customized view and InAppMessaging default view.
There is only one step to start using 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
Just add your Cartfile
github "fumito-ito/SwiftyInAppMessaging" ~> 2.0.0
and run carthage update
Just add to your Package.swift
under dependencies
let package = Package(
name: "MyPackage",
products: [...],
dependencies: [
.package(url: "https://github.com/fumito-ito/SwiftyInAppMessaging.git", .upToNextMajor(from: "2.0.0"))
]
)
Just add to your Podfile
pod 'SwiftyInAppMessaging'
and run pod install
If you have errors about Double-quoted include "*.h" in framework header, expected angle-bracketed instead
, you can avoid these errors with following steps.
- update your cocoapods
1.10
or later - run
pod install
again
- Click
Pods
project - Click Project's
Build Settings
- Change
Quoted include in Framework Header
toNo
For more information, see a firebase-ios-sdk issue.
SwiftyInAppMessaging is available under the Apache License 2.0. See the LICENSE file for more detail.