-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
662 additions
and
514 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,85 @@ | ||
import UIKit | ||
import Appboy_iOS_SDK | ||
import BrazeKit | ||
import BrazeLocation | ||
import BrazeUI | ||
import Flutter | ||
import SDWebImage | ||
import UIKit | ||
import braze_plugin | ||
|
||
let apiKey = "9292484d-3b10-4e67-971d-ff0c0d518e21" | ||
let brazeApiKey = "9292484d-3b10-4e67-971d-ff0c0d518e21" | ||
let brazeEndpoint = "sondheim.appboy.com" | ||
|
||
@UIApplicationMain | ||
@objc class AppDelegate: FlutterAppDelegate, ABKInAppMessageControllerDelegate { | ||
@objc class AppDelegate: FlutterAppDelegate, BrazeInAppMessageUIDelegate { | ||
|
||
static var braze: Braze? = nil | ||
|
||
// The subscription needs to be retained to be active | ||
var contentCardsSubscription: Braze.Cancellable? | ||
|
||
override func application(_ application: UIApplication, | ||
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? | ||
override func application( | ||
_ application: UIApplication, | ||
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? | ||
) -> Bool { | ||
GeneratedPluginRegistrant.register(with: self) | ||
|
||
Appboy.start(withApiKey: apiKey, | ||
in:application, | ||
withLaunchOptions:launchOptions, | ||
withAppboyOptions: [ABKMinimumTriggerTimeIntervalKey : 1, | ||
ABKEnableSDKAuthenticationKey : true]) | ||
Appboy.sharedInstance()!.inAppMessageController.delegate = self | ||
// - Setup Braze | ||
let configuration = Braze.Configuration(apiKey: brazeApiKey, endpoint: brazeEndpoint) | ||
configuration.sessionTimeout = 1 | ||
configuration.triggerMinimumTimeInterval = 0 | ||
configuration.location.automaticLocationCollection = true | ||
configuration.location.brazeLocation = BrazeLocation() | ||
configuration.logger.level = .debug | ||
|
||
let braze = BrazePlugin.initBraze(configuration) | ||
|
||
// - GIF support | ||
GIFViewProvider.shared = .sdWebImage | ||
|
||
// - InAppMessage UI | ||
let inAppMessageUI = BrazeInAppMessageUI() | ||
inAppMessageUI.delegate = self | ||
braze.inAppMessagePresenter = inAppMessageUI | ||
|
||
contentCardsSubscription = braze.contentCards.subscribeToUpdates { contentCards in | ||
print("=> [Content Card Subscription] Received cards:", contentCards) | ||
|
||
NotificationCenter.default.addObserver(self, selector: #selector(contentCardsUpdated), name:NSNotification.Name.ABKContentCardsProcessed, object: nil) | ||
// Pass each content card model to the Dart layer. | ||
BrazePlugin.processContentCards(contentCards) | ||
} | ||
|
||
return super.application(application, didFinishLaunchingWithOptions: launchOptions) | ||
} | ||
|
||
func before(inAppMessageDisplayed inAppMessage: ABKInAppMessage) -> ABKInAppMessageDisplayChoice { | ||
print("Received in-app message from Braze in beforeInAppMessageDisplayed delegate.") | ||
// MARK: BrazeInAppMessageUIDelegate | ||
|
||
// Pass in-app data to the Flutter layer. | ||
BrazePlugin.processInAppMessage(inAppMessage) | ||
func inAppMessage( | ||
_ ui: BrazeInAppMessageUI, | ||
willPresent message: Braze.InAppMessage, | ||
view: InAppMessageView | ||
) { | ||
print("=> [In-app Message] Received message from Braze:", message) | ||
|
||
// Note: return ABKInAppMessageDisplayChoice.discardInAppMessage if you would like | ||
// to prevent the Braze SDK from displaying the message natively. | ||
return ABKInAppMessageDisplayChoice.displayInAppMessageNow | ||
// Pass in-app message data to the Dart layer. | ||
BrazePlugin.processInAppMessage(message) | ||
} | ||
|
||
@objc private func contentCardsUpdated(_ notification: Notification) { | ||
guard (notification.userInfo?[ABKContentCardsProcessedIsSuccessfulKey] as? Bool) == true, | ||
let appboy = Appboy.sharedInstance() else { | ||
return | ||
} | ||
|
||
// Pass in-app data to the Flutter layer. | ||
let contentCards = appboy.contentCardsController.contentCards.compactMap { $0 as? ABKContentCard } | ||
BrazePlugin.processContentCards(contentCards) | ||
} | ||
|
||
// MARK: GIF support | ||
|
||
extension GIFViewProvider { | ||
|
||
public static let sdWebImage = Self( | ||
view: { SDAnimatedImageView(image: image(for: $0)) }, | ||
updateView: { ($0 as? SDAnimatedImageView)?.image = image(for: $1) } | ||
) | ||
|
||
private static func image(for url: URL?) -> UIImage? { | ||
guard let url = url else { return nil } | ||
return url.pathExtension == "gif" | ||
? SDAnimatedImage(contentsOfFile: url.path) | ||
: UIImage(contentsOfFile: url.path) | ||
} | ||
|
||
} |
Oops, something went wrong.