From 38ae936f6de96f16a7aff60d8120283303239ab6 Mon Sep 17 00:00:00 2001 From: Ben Baron Date: Tue, 15 Oct 2024 09:45:28 -0500 Subject: [PATCH 1/4] fix: Build error and warning --- .../HiggsShopSampleApp/AppDelegate.swift | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/AppDelegate.swift b/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/AppDelegate.swift index 550ae40..bd35023 100644 --- a/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/AppDelegate.swift +++ b/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/AppDelegate.swift @@ -32,15 +32,18 @@ final class AppDelegate: UIResponder, UIApplicationDelegate, MPListenerProtocol } } if let options = makeOptions() { - if let reset = parseBool(getConfigInfo("MPARTICLE_RESET")) { - if reset == true { - MParticle.sharedInstance().reset() + let completion = { + if let optOut = self.parseBool(self.getConfigInfo("MPARTICLE_OPTOUT")) { + MParticle.sharedInstance().optOut = optOut } + MParticle.sharedInstance().start(with: options) } - if let optOut = parseBool(getConfigInfo("MPARTICLE_OPTOUT")) { - MParticle.sharedInstance().optOut = optOut + + if let reset = parseBool(getConfigInfo("MPARTICLE_RESET")), reset == true { + MParticle.sharedInstance().reset(completion) + } else { + completion() } - MParticle.sharedInstance().start(with: options) } else { log("Error: Unable to create mParticle Options object") } @@ -102,7 +105,7 @@ final class AppDelegate: UIResponder, UIApplicationDelegate, MPListenerProtocol // Sideloaded kits are simply classes that conform to MPKitProtocol and can be used to receive callbacks when various things happen such as events being logged. // This example is a simple implementation that only logs the callbacks to the console, but the data in the callbacks can be used for anything. // NOTE: Sideloaded kits are always active regardless of server-side configuration. - options.sideloadedKits = [ConsoleLoggingKit()] + options.sideloadedKits = [MPSideloadedKit(kitInstance: ConsoleLoggingKit())] return options } From 2a54fc2713792169a2383a7b22f438c1c15ac2fa Mon Sep 17 00:00:00 2001 From: Ben Baron Date: Tue, 15 Oct 2024 10:03:54 -0500 Subject: [PATCH 2/4] Fix swiftlint errors --- .../HiggsShopSampleApp/CheckoutViewController.swift | 2 +- .../HiggsShopSampleApp/LandingViewController.swift | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/CheckoutViewController.swift b/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/CheckoutViewController.swift index 0a248ac..0aa5623 100644 --- a/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/CheckoutViewController.swift +++ b/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/CheckoutViewController.swift @@ -469,7 +469,7 @@ final class CheckoutViewController: UIViewController, UITextFieldDelegate, UIScr // Present Purchase Confirmation let purchaseMessage = UIAlertController(title: NSLocalizedString("Purchase Complete", comment: ""), message: NSLocalizedString("No actual purchase has been made.", comment: ""), preferredStyle: .alert) - let okAction = UIAlertAction(title: "OK", style: .default, handler: { (_) -> Void in + let okAction = UIAlertAction(title: "OK", style: .default, handler: { _ in self.navigationController?.popViewController(animated: true) }) purchaseMessage.addAction(okAction) diff --git a/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/LandingViewController.swift b/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/LandingViewController.swift index 0c56216..05ec799 100644 --- a/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/LandingViewController.swift +++ b/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/LandingViewController.swift @@ -94,12 +94,12 @@ final class LandingViewController: UIViewController { private func showCredsAlert() { let keysAlertMessage = UIAlertController(title: NSLocalizedString("AlertKeysMissingTitle", comment: ""), message: NSLocalizedString("AlertKeysMissingMessage", comment: ""), preferredStyle: .alert) - let dismissAction = UIAlertAction(title: NSLocalizedString("AlertKeysMissingDismissLabel", comment: ""), style: .default, handler: { (_) -> Void in + let dismissAction = UIAlertAction(title: NSLocalizedString("AlertKeysMissingDismissLabel", comment: ""), style: .default, handler: { _ in self.navigationController?.popViewController(animated: true) exit(1) }) dismissAction.accessibilityIdentifier = "AlertKeysMissingDismissLabel" - let docsAction = UIAlertAction(title: NSLocalizedString("AlertKeysMissingDocsLabel", comment: ""), style: .default, handler: { (_) -> Void in + let docsAction = UIAlertAction(title: NSLocalizedString("AlertKeysMissingDocsLabel", comment: ""), style: .default, handler: { _ in self.navigationController?.popViewController(animated: true) let url = URL(string: NSLocalizedString("AlertKeysMissingDocsURL", comment: "")) if let url = url { From b75b11b0ddc0cfed982d00f76228e815d53c3b2f Mon Sep 17 00:00:00 2001 From: Ben Baron Date: Tue, 15 Oct 2024 10:59:10 -0500 Subject: [PATCH 3/4] Fix more linting stuff --- .../higgs-shop-sample-app-pull-request.yml | 14 +-- .swiftlint.yml | 5 ++ .../HiggsShopSampleApp/AppDelegate.swift | 14 +-- .../HiggsShopSampleApp/CartTableCell.swift | 18 ++-- .../CartViewController.swift | 38 ++++---- .../CheckoutViewController.swift | 88 +++++++++---------- .../HiggsShopSampleApp/LabeledTextField.swift | 6 +- .../LandingViewController.swift | 16 ++-- .../MyAccountViewController.swift | 36 ++++---- .../HiggsShopSampleApp/Product.swift | 4 +- .../ProductDetailViewController.swift | 46 +++++----- .../HiggsShopSampleApp/SceneDelegate.swift | 2 +- .../HiggsShopSampleApp/ShopTableCell.swift | 14 +-- .../ShopViewController.swift | 16 ++-- .../HiggsShopSampleApp/TabBarController.swift | 6 +- .../HiggsShopSampleApp/Utils.swift | 14 +-- .../mp-sideloaded-kit-example/Package.swift | 8 +- .../src/ConsoleLoggingKit.swift | 18 ++-- 18 files changed, 185 insertions(+), 178 deletions(-) create mode 100644 .swiftlint.yml diff --git a/.github/workflows/higgs-shop-sample-app-pull-request.yml b/.github/workflows/higgs-shop-sample-app-pull-request.yml index 1071834..d9c008f 100644 --- a/.github/workflows/higgs-shop-sample-app-pull-request.yml +++ b/.github/workflows/higgs-shop-sample-app-pull-request.yml @@ -11,16 +11,18 @@ jobs: runs-on: macos-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Run swiftlint - run: swiftlint + run: | + brew install swiftlint + swiftlint ui-tests: runs-on: macos-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Run UI tests run: xcodebuild test -project HiggsShopSampleApp.xcodeproj -destination "platform=iOS Simulator,name=iPhone 12,OS=latest" -scheme HiggsShopSampleApp @@ -29,7 +31,7 @@ jobs: runs-on: macos-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Run tests with thread sanitizer run: xcodebuild test -project HiggsShopSampleApp.xcodeproj -destination "platform=iOS Simulator,name=iPhone 12,OS=latest" -scheme HiggsShopSampleApp -enableThreadSanitizer YES @@ -39,7 +41,7 @@ jobs: runs-on: macos-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Run tests with address sanitizer run: xcodebuild test -project HiggsShopSampleApp.xcodeproj -destination "platform=iOS Simulator,name=iPhone 12,OS=latest" -scheme HiggsShopSampleApp -enableAddressSanitizer YES @@ -48,7 +50,7 @@ jobs: runs-on: macos-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Run static analyzer run: xcodebuild analyze -project HiggsShopSampleApp.xcodeproj -scheme HiggsShopSampleApp -destination "platform=iOS Simulator,name=iPhone 12,OS=latest" diff --git a/.swiftlint.yml b/.swiftlint.yml new file mode 100644 index 0000000..935fb11 --- /dev/null +++ b/.swiftlint.yml @@ -0,0 +1,5 @@ +disabled_rules: + - function_body_length + - type_body_length + - line_length + - file_length \ No newline at end of file diff --git a/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/AppDelegate.swift b/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/AppDelegate.swift index bd35023..de061d0 100644 --- a/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/AppDelegate.swift +++ b/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/AppDelegate.swift @@ -17,7 +17,7 @@ final class AppDelegate: UIResponder, UIApplicationDelegate, MPListenerProtocol func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { } - + func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask { return .portrait } @@ -38,7 +38,7 @@ final class AppDelegate: UIResponder, UIApplicationDelegate, MPListenerProtocol } MParticle.sharedInstance().start(with: options) } - + if let reset = parseBool(getConfigInfo("MPARTICLE_RESET")), reset == true { MParticle.sharedInstance().reset(completion) } else { @@ -47,7 +47,7 @@ final class AppDelegate: UIResponder, UIApplicationDelegate, MPListenerProtocol } else { log("Error: Unable to create mParticle Options object") } - + UITabBarItem.appearance().setTitleTextAttributes([.font: Utils.font(ofSize: 12)], for: .normal) UITabBarItem.appearance().setTitleTextAttributes([.font: Utils.font(ofSize: 12)], for: .selected) UITabBarItem.appearance().setTitleTextAttributes([.font: Utils.font(ofSize: 12)], for: .highlighted) @@ -101,12 +101,12 @@ final class AppDelegate: UIResponder, UIApplicationDelegate, MPListenerProtocol options.proxyAppDelegate = false } } - + // Sideloaded kits are simply classes that conform to MPKitProtocol and can be used to receive callbacks when various things happen such as events being logged. // This example is a simple implementation that only logs the callbacks to the console, but the data in the callbacks can be used for anything. // NOTE: Sideloaded kits are always active regardless of server-side configuration. options.sideloadedKits = [MPSideloadedKit(kitInstance: ConsoleLoggingKit())] - + return options } @@ -160,7 +160,7 @@ final class AppDelegate: UIResponder, UIApplicationDelegate, MPListenerProtocol } return nil } - + // This code allows us to create predefined Schemes with with different settings and accounts for MParticleOptions. If you would like to use schemes in this way for simulator testing, add these keys as 'Environment Variables' under the 'Arguments' section of the 'Run' tab of the scheme. func getOverrideConfig(_ key: String) -> String? { #if targetEnvironment(simulator) @@ -179,7 +179,7 @@ final class AppDelegate: UIResponder, UIApplicationDelegate, MPListenerProtocol if overrideValue == "REPLACEME" { overrideValue = nil } - + var shouldOverride = true if let disableOverride = parseBool(getDefaultConfig("CONFIG_DISABLEOVERRIDE")), disableOverride { shouldOverride = false diff --git a/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/CartTableCell.swift b/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/CartTableCell.swift index b4540d7..6286bc0 100644 --- a/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/CartTableCell.swift +++ b/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/CartTableCell.swift @@ -3,13 +3,13 @@ import SnapKit final class CartTableCell: UITableViewCell { static let reuseId = "CartTableCell" - + let productImageView = UIImageView() let productNameLabel = UILabel() let productDetailLabel = UILabel() let productPriceLabel = UILabel() let removeProductButton = UIButton() - + var cartItem: CartItem? { didSet { if let cartItem = cartItem { @@ -26,10 +26,10 @@ final class CartTableCell: UITableViewCell { } } } - + override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) - + productImageView.accessibilityIdentifier = "CartCellProductImageView" productImageView.contentMode = .scaleAspectFill addSubview(productImageView) @@ -39,7 +39,7 @@ final class CartTableCell: UITableViewCell { make.bottom.equalTo(self.snp.bottom).offset(-16) make.width.equalTo(100) } - + productNameLabel.accessibilityIdentifier = "CartCellProductNameLabel" productNameLabel.textColor = .label productNameLabel.font = Utils.font(ofSize: 16) @@ -52,7 +52,7 @@ final class CartTableCell: UITableViewCell { make.height.equalTo(24).priority(.high) make.trailing.equalTo(productPriceLabel.snp.leading).offset(-5) } - + productPriceLabel.accessibilityIdentifier = "CartCellProductPriceLabel" productPriceLabel.textColor = .label productPriceLabel.font = Utils.font(ofSize: 15) @@ -62,7 +62,7 @@ final class CartTableCell: UITableViewCell { make.trailing.equalTo(self.snp.trailing).offset(-32) make.height.equalTo(16) } - + productDetailLabel.accessibilityIdentifier = "CartCellProductDetailLabel" productDetailLabel.textColor = .secondaryLabel productDetailLabel.font = Utils.font(ofSize: 14) @@ -73,7 +73,7 @@ final class CartTableCell: UITableViewCell { make.leading.equalTo(productImageView.snp.trailing).offset(20) make.height.equalTo(20) } - + addSubview(removeProductButton) removeProductButton.snp.makeConstraints { make in make.top.equalTo(productDetailLabel.snp.bottom) @@ -88,7 +88,7 @@ final class CartTableCell: UITableViewCell { removeProductButton.layer.borderWidth = 0 removeProductButton.contentHorizontalAlignment = .left } - + required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } diff --git a/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/CartViewController.swift b/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/CartViewController.swift index 6b661e3..da8ed3b 100644 --- a/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/CartViewController.swift +++ b/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/CartViewController.swift @@ -6,10 +6,10 @@ final class CartViewController: UITableViewController { let subtotalLabel = UILabel() let subtotalValueLabel = UILabel() let subtotalDivider = UIView() - + let checkoutButton = UIButton() let checkoutDisclaimerLabel = UILabel() - + override func viewDidLoad() { navigationItem.title = "My Cart" edgesForExtendedLayout = [] @@ -18,27 +18,27 @@ final class CartViewController: UITableViewController { for item in AppDelegate.cart.items { subTotal += Double(item.quantity) * item.product.price } - + // Renders an initial cart view when the screen loads MParticle.sharedInstance().logScreen("View My Cart", eventInfo: ["number_of_products": numberOfProducts, "total_product_amounts": subTotal]) - + tableView.accessibilityIdentifier = "CartTableView" tableView.register(CartTableCell.self, forCellReuseIdentifier: CartTableCell.reuseId) tableView.rowHeight = UITableView.automaticDimension tableView.estimatedRowHeight = 80 - + calculateCosts() } - + override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) reloadTable() calculateCosts() } - + private func reloadTable() { tableView.reloadData() - + let count = AppDelegate.cart.items.count tabBarController?.tabBar.items?.last?.badgeValue = (count == 0 ? nil : "\(AppDelegate.cart.items.count)") @@ -56,7 +56,7 @@ final class CartViewController: UITableViewController { tableView.tableHeaderView = nil let footerView = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.width, height: 164)) footerView.backgroundColor = UIColor.clear - + footerView.addSubview(subtotalLabel) subtotalLabel.snp.makeConstraints { make in make.top.equalTo(footerView.snp.top).offset(14) @@ -86,7 +86,7 @@ final class CartViewController: UITableViewController { make.trailing.equalTo(footerView.snp.trailing).offset(-16) } subtotalDivider.backgroundColor = .separator - + footerView.addSubview(checkoutButton) checkoutButton.snp.makeConstraints { make in make.top.equalTo(subtotalDivider.snp.bottom).offset(38) @@ -99,7 +99,7 @@ final class CartViewController: UITableViewController { checkoutButton.backgroundColor = UIColor(red: 64/255.0, green: 121/255.0, blue: 254/255.0, alpha: 1.0) checkoutButton.layer.cornerRadius = 8 checkoutButton.titleLabel?.font = Utils.font(ofSize: 16) - + footerView.addSubview(checkoutDisclaimerLabel) checkoutDisclaimerLabel.snp.makeConstraints { make in make.top.equalTo(checkoutButton.snp.bottom).offset(19) @@ -111,17 +111,17 @@ final class CartViewController: UITableViewController { checkoutDisclaimerLabel.font = Utils.font(ofSize: 12) checkoutDisclaimerLabel.textAlignment = .center checkoutDisclaimerLabel.textColor = .secondaryLabel - + footerView.frame.size.height = 164 tableView.tableFooterView = footerView tableView.isScrollEnabled = true } } - + override func numberOfSections(in tableView: UITableView) -> Int { return 1 } - + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return AppDelegate.cart.items.count } @@ -136,7 +136,7 @@ final class CartViewController: UITableViewController { cartTableCell.cartItem = AppDelegate.cart.items[indexPath.row] return cartTableCell } - + override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { let removedItem = AppDelegate.cart.items.remove(at: indexPath.row) let detailView = ProductDetailViewController(product: removedItem.product) @@ -148,17 +148,17 @@ final class CartViewController: UITableViewController { event.shouldBeginSession = AppDelegate.eventsBeginSessions MParticle.sharedInstance().logEvent(event) } - + private func calculateCosts() { var subtotal = 0.00 for cartItem in AppDelegate.cart.items { subtotal += cartItem.totalAmount } - + subtotalValueLabel.text = "$" + String(format: "%.2f", subtotal) checkoutButton.isEnabled = subtotal != 0 } - + @objc private func checkout() { if let event = MPCommerceEvent(action: .checkout) { var products = [MPProduct]() @@ -189,7 +189,7 @@ final class CartViewController: UITableViewController { event.transactionAttributes = transactionAttributes // transaction attributes are required event.shouldBeginSession = AppDelegate.eventsBeginSessions MParticle.sharedInstance().logEvent(event) - + let checkoutVC = CheckoutViewController() checkoutVC.hidesBottomBarWhenPushed = true navigationController?.pushViewController(checkoutVC, animated: true) diff --git a/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/CheckoutViewController.swift b/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/CheckoutViewController.swift index 0aa5623..ede236d 100644 --- a/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/CheckoutViewController.swift +++ b/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/CheckoutViewController.swift @@ -4,48 +4,48 @@ import mParticle_Apple_SDK final class CheckoutViewController: UIViewController, UITextFieldDelegate, UIScrollViewDelegate, UITableViewDelegate, UITableViewDataSource { let scrollView = UIScrollView() - + let checkoutLabel = UILabel() - + let shippingLabel = UILabel() let shippingDisclaimerLabel = UILabel() - + let streetAddressTextbox = LabeledTextField() let cityTextbox = LabeledTextField() let stateTextbox = LabeledTextField() let zipTextbox = LabeledTextField() - + let paymentLabel = UILabel() let paymentDisclaimerLabel = UILabel() - + let creditCardTextbox = LabeledTextField() let expirationTextbox = LabeledTextField() let cardVerificationTextbox = LabeledTextField() - + let reviewOrderLabel = UILabel() - + let cartTableView = UITableView() - + let subtotalLabel = UILabel() let subtotalValueLabel = UILabel() let subtotalDivider = UIView() - + let salesTaxLabel = UILabel() let salesTaxValueLabel = UILabel() let salesTaxDivider = UIView() - + let shippingCostLabel = UILabel() let shippingCostValueLabel = UILabel() let shippingCostDivider = UIView() - + let grandTotalLabel = UILabel() let grandTotalValueLabel = UILabel() let grandTotalDivider = UIView() let grandTotalHighlight = UIView() - + let placeOrderButton = UIButton() let placeOrderDisclaimerLabel = UILabel() - + override func viewDidLoad() { view.addSubview(scrollView) scrollView.delegate = self @@ -56,7 +56,7 @@ final class CheckoutViewController: UIViewController, UITextFieldDelegate, UIScr make.leading.equalToSuperview() make.trailing.equalToSuperview() } - + scrollView.addSubview(checkoutLabel) checkoutLabel.text = NSLocalizedString("CheckoutTitle", comment: "") checkoutLabel.font = Utils.boldFont(ofSize: 24) @@ -67,7 +67,7 @@ final class CheckoutViewController: UIViewController, UITextFieldDelegate, UIScr make.leading.equalTo(self.view).offset(17) make.trailing.equalTo(self.view).offset(-17) } - + scrollView.addSubview(shippingLabel) shippingLabel.text = NSLocalizedString("CheckoutSubtitleShipping", comment: "") shippingLabel.font = Utils.font(ofSize: 20) @@ -78,7 +78,7 @@ final class CheckoutViewController: UIViewController, UITextFieldDelegate, UIScr make.leading.equalTo(checkoutLabel.snp.leading) make.trailing.equalTo(checkoutLabel.snp.trailing) } - + scrollView.addSubview(shippingDisclaimerLabel) shippingDisclaimerLabel.text = NSLocalizedString("CheckoutDemoOnly", comment: "") shippingDisclaimerLabel.font = Utils.font(ofSize: 12) @@ -90,7 +90,7 @@ final class CheckoutViewController: UIViewController, UITextFieldDelegate, UIScr make.leading.equalTo(checkoutLabel.snp.leading) make.trailing.equalTo(checkoutLabel.snp.trailing) } - + scrollView.addSubview(streetAddressTextbox) streetAddressTextbox.snp.makeConstraints { make in make.top.equalTo(shippingDisclaimerLabel.snp.bottom).offset(16) @@ -102,7 +102,7 @@ final class CheckoutViewController: UIViewController, UITextFieldDelegate, UIScr streetAddressTextbox.textBoxField.delegate = self streetAddressTextbox.textBoxLabel.text = NSLocalizedString("CheckoutStreetAddressLabel", comment: "") streetAddressTextbox.textBoxField.text = NSLocalizedString("CheckoutStreetAddressDefault", comment: "") - + scrollView.addSubview(cityTextbox) cityTextbox.snp.makeConstraints { make in make.top.equalTo(streetAddressTextbox.snp.bottom).offset(20) @@ -114,7 +114,7 @@ final class CheckoutViewController: UIViewController, UITextFieldDelegate, UIScr cityTextbox.textBoxField.delegate = self cityTextbox.textBoxLabel.text = NSLocalizedString("CheckoutCityAddressLabel", comment: "") cityTextbox.textBoxField.text = NSLocalizedString("CheckoutCityAddressDefault", comment: "") - + scrollView.addSubview(stateTextbox) stateTextbox.snp.makeConstraints { make in make.top.equalTo(cityTextbox.snp.bottom).offset(20) @@ -126,7 +126,7 @@ final class CheckoutViewController: UIViewController, UITextFieldDelegate, UIScr stateTextbox.textBoxField.delegate = self stateTextbox.textBoxLabel.text = NSLocalizedString("CheckoutStateAddressLabel", comment: "") stateTextbox.textBoxField.text = NSLocalizedString("CheckoutStateAddressDefault", comment: "") - + scrollView.addSubview(zipTextbox) zipTextbox.snp.makeConstraints { make in make.top.equalTo(cityTextbox.snp.bottom).offset(20) @@ -138,7 +138,7 @@ final class CheckoutViewController: UIViewController, UITextFieldDelegate, UIScr zipTextbox.textBoxField.delegate = self zipTextbox.textBoxLabel.text = NSLocalizedString("CheckoutZipAddressLabel", comment: "") zipTextbox.textBoxField.text = NSLocalizedString("CheckoutZipAddressDefault", comment: "") - + scrollView.addSubview(paymentLabel) paymentLabel.snp.makeConstraints { make in make.top.equalTo(zipTextbox.snp.bottom).offset(45) @@ -149,7 +149,7 @@ final class CheckoutViewController: UIViewController, UITextFieldDelegate, UIScr paymentLabel.text = NSLocalizedString("CheckoutSubtitlePayment", comment: "") paymentLabel.font = Utils.font(ofSize: 20) paymentLabel.textAlignment = .center - + scrollView.addSubview(paymentDisclaimerLabel) paymentDisclaimerLabel.snp.makeConstraints { make in make.top.equalTo(paymentLabel.snp.bottom) @@ -159,7 +159,7 @@ final class CheckoutViewController: UIViewController, UITextFieldDelegate, UIScr paymentDisclaimerLabel.font = Utils.font(ofSize: 12) paymentDisclaimerLabel.textAlignment = .center paymentDisclaimerLabel.textColor = .secondaryLabel - + scrollView.addSubview(creditCardTextbox) creditCardTextbox.snp.makeConstraints { make in make.top.equalTo(paymentDisclaimerLabel.snp.bottom).offset(16) @@ -171,7 +171,7 @@ final class CheckoutViewController: UIViewController, UITextFieldDelegate, UIScr creditCardTextbox.textBoxField.delegate = self creditCardTextbox.textBoxLabel.text = NSLocalizedString("CheckoutCreditCardNumberLabel", comment: "") creditCardTextbox.textBoxField.text = NSLocalizedString("CheckoutCreditCardNumberDefault", comment: "") - + scrollView.addSubview(expirationTextbox) expirationTextbox.snp.makeConstraints { make in make.top.equalTo(creditCardTextbox.snp.bottom).offset(20) @@ -183,7 +183,7 @@ final class CheckoutViewController: UIViewController, UITextFieldDelegate, UIScr expirationTextbox.textBoxField.delegate = self expirationTextbox.textBoxLabel.text = NSLocalizedString("CheckoutCreditCardExpDateLabel", comment: "") expirationTextbox.textBoxField.text = NSLocalizedString("CheckoutCreditCardExpDateDefault", comment: "") - + scrollView.addSubview(cardVerificationTextbox) cardVerificationTextbox.snp.makeConstraints { make in make.top.equalTo(creditCardTextbox.snp.bottom).offset(20) @@ -195,7 +195,7 @@ final class CheckoutViewController: UIViewController, UITextFieldDelegate, UIScr cardVerificationTextbox.textBoxField.delegate = self cardVerificationTextbox.textBoxLabel.text = NSLocalizedString("CheckoutCreditCardCVCLabel", comment: "") cardVerificationTextbox.textBoxField.text = NSLocalizedString("CheckoutCreditCardCVCDefault", comment: "") - + scrollView.addSubview(reviewOrderLabel) reviewOrderLabel.snp.makeConstraints { make in make.top.equalTo(expirationTextbox.snp.bottom).offset(45) @@ -206,7 +206,7 @@ final class CheckoutViewController: UIViewController, UITextFieldDelegate, UIScr reviewOrderLabel.text = NSLocalizedString("CheckoutSubtitleReviewOrder", comment: "") reviewOrderLabel.font = Utils.font(ofSize: 20) reviewOrderLabel.textAlignment = .center - + scrollView.addSubview(cartTableView) cartTableView.snp.makeConstraints { make in make.top.equalTo(reviewOrderLabel.snp.bottom).offset(14) @@ -221,7 +221,7 @@ final class CheckoutViewController: UIViewController, UITextFieldDelegate, UIScr cartTableView.delegate = self cartTableView.dataSource = self cartTableView.reloadData() - + scrollView.addSubview(subtotalLabel) subtotalLabel.snp.makeConstraints { make in make.top.equalTo(cartTableView.snp.bottom).offset(14) @@ -283,7 +283,7 @@ final class CheckoutViewController: UIViewController, UITextFieldDelegate, UIScr make.trailing.equalTo(self.view.snp.trailing).offset(-16) } salesTaxDivider.backgroundColor = .separator - + scrollView.addSubview(shippingCostLabel) shippingCostLabel.snp.makeConstraints { make in make.top.equalTo(salesTaxDivider.snp.bottom).offset(14) @@ -314,7 +314,7 @@ final class CheckoutViewController: UIViewController, UITextFieldDelegate, UIScr make.trailing.equalTo(self.view.snp.trailing).offset(-16) } shippingCostDivider.backgroundColor = .separator - + scrollView.addSubview(grandTotalLabel) grandTotalLabel.snp.makeConstraints { make in make.top.equalTo(shippingCostDivider.snp.bottom).offset(14) @@ -345,7 +345,7 @@ final class CheckoutViewController: UIViewController, UITextFieldDelegate, UIScr make.trailing.equalTo(self.view.snp.trailing).offset(-16) } grandTotalDivider.backgroundColor = .separator - + scrollView.addSubview(grandTotalHighlight) grandTotalHighlight.snp.makeConstraints { make in make.top.equalTo(shippingCostDivider.snp.bottom) @@ -355,7 +355,7 @@ final class CheckoutViewController: UIViewController, UITextFieldDelegate, UIScr } grandTotalHighlight.backgroundColor = .separator scrollView.sendSubviewToBack(grandTotalHighlight) - + scrollView.addSubview(placeOrderButton) placeOrderButton.snp.makeConstraints { make in make.top.equalTo(grandTotalDivider.snp.bottom).offset(38) @@ -368,7 +368,7 @@ final class CheckoutViewController: UIViewController, UITextFieldDelegate, UIScr placeOrderButton.backgroundColor = UIColor(red: 64/255.0, green: 121/255.0, blue: 254/255.0, alpha: 1.0) placeOrderButton.layer.cornerRadius = 8 placeOrderButton.titleLabel?.font = Utils.font(ofSize: 16) - + scrollView.addSubview(placeOrderDisclaimerLabel) placeOrderDisclaimerLabel.snp.makeConstraints { make in make.top.equalTo(placeOrderButton.snp.bottom) @@ -381,16 +381,16 @@ final class CheckoutViewController: UIViewController, UITextFieldDelegate, UIScr placeOrderDisclaimerLabel.font = Utils.font(ofSize: 12) placeOrderDisclaimerLabel.textAlignment = .center placeOrderDisclaimerLabel.textColor = .secondaryLabel - + calculateCosts() - + MParticle.sharedInstance().logScreen("Checkout", eventInfo: nil) } - + func numberOfSections(in tableView: UITableView) -> Int { return 1 } - + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return AppDelegate.cart.items.count } @@ -405,7 +405,7 @@ final class CheckoutViewController: UIViewController, UITextFieldDelegate, UIScr cartTableCell.cartItem = AppDelegate.cart.items[indexPath.row] return cartTableCell } - + func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { let removedItem = AppDelegate.cart.items.remove(at: indexPath.row) let detailView = ProductDetailViewController(product: removedItem.product) @@ -417,7 +417,7 @@ final class CheckoutViewController: UIViewController, UITextFieldDelegate, UIScr event.shouldBeginSession = AppDelegate.eventsBeginSessions MParticle.sharedInstance().logEvent(event) } - + private func calculateCosts() { var subtotal = 0.00 for cartItem in AppDelegate.cart.items { @@ -425,14 +425,14 @@ final class CheckoutViewController: UIViewController, UITextFieldDelegate, UIScr } let taxTotal = subtotal * 0.08875 let shippingTotal = subtotal * 0.15 - + subtotalValueLabel.text = "$" + String(format: "%.2f", subtotal) salesTaxValueLabel.text = "$" + String(format: "%.2f", taxTotal) shippingCostValueLabel.text = "$" + String(format: "%.2f", shippingTotal) grandTotalValueLabel.text = "$" + String(format: "%.2f", subtotal + taxTotal + shippingTotal) placeOrderButton.isEnabled = subtotal != 0 } - + @objc private func placeOrder() { print("place order") if let event = MPCommerceEvent(action: .purchase) { @@ -463,10 +463,10 @@ final class CheckoutViewController: UIViewController, UITextFieldDelegate, UIScr event.transactionAttributes = transactionAttributes // transaction attributes are required event.shouldBeginSession = AppDelegate.eventsBeginSessions MParticle.sharedInstance().logEvent(event) - + // Clear the cart AppDelegate.cart.items.removeAll() - + // Present Purchase Confirmation let purchaseMessage = UIAlertController(title: NSLocalizedString("Purchase Complete", comment: ""), message: NSLocalizedString("No actual purchase has been made.", comment: ""), preferredStyle: .alert) let okAction = UIAlertAction(title: "OK", style: .default, handler: { _ in @@ -476,7 +476,7 @@ final class CheckoutViewController: UIViewController, UITextFieldDelegate, UIScr self.present(purchaseMessage, animated: true, completion: nil) } } - + @objc func textFieldShouldReturn(_ textField: UITextField) -> Bool { streetAddressTextbox.textBoxField.resignFirstResponder() cityTextbox.textBoxField.resignFirstResponder() diff --git a/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/LabeledTextField.swift b/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/LabeledTextField.swift index 13affa0..383c7fe 100644 --- a/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/LabeledTextField.swift +++ b/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/LabeledTextField.swift @@ -3,10 +3,10 @@ import SnapKit final class LabeledTextField: UIView { static let reuseId = "CartTableCell" - + let textBoxField = UITextField() let textBoxLabel = UILabel() - + override init(frame: CGRect) { super.init(frame: frame) sharedLayout() @@ -36,7 +36,7 @@ final class LabeledTextField: UIView { textBoxField.layer.borderWidth = 1.0 textBoxField.layer.cornerRadius = 3.5 textBoxField.returnKeyType = .done - + self.addSubview(textBoxLabel) textBoxLabel.snp.makeConstraints { make in make.top.equalTo(self) diff --git a/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/LandingViewController.swift b/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/LandingViewController.swift index 05ec799..c92812b 100644 --- a/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/LandingViewController.swift +++ b/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/LandingViewController.swift @@ -8,7 +8,7 @@ final class LandingViewController: UIViewController { let welcomeLabel = UILabel() let storeButton = UIButton(type: .custom) let disclaimerLabel = UILabel() - + override func viewDidLoad() { backgroundImageView.accessibilityIdentifier = "LandingBackgroundImageView" backgroundImageView.image = UIImage(named: "BackgroundGradient") @@ -17,7 +17,7 @@ final class LandingViewController: UIViewController { backgroundImageView.snp.makeConstraints { make in make.edges.equalToSuperview() } - + higgsImageView.accessibilityIdentifier = "HiggsWelcomeLogo" higgsImageView.image = UIImage(named: "HiggsWelcomeLogo") higgsImageView.contentMode = .scaleAspectFit @@ -27,7 +27,7 @@ final class LandingViewController: UIViewController { make.centerY.equalToSuperview().multipliedBy(0.5) make.width.height.equalTo(250) } - + welcomeLabel.accessibilityIdentifier = "WelcomeLabel" welcomeLabel.textColor = .label welcomeLabel.text = NSLocalizedString("LandingWelcome", comment: "") @@ -40,7 +40,7 @@ final class LandingViewController: UIViewController { make.width.equalToSuperview().multipliedBy(0.8) make.centerX.equalToSuperview() } - + storeButton.accessibilityIdentifier = "LandingCTA" storeButton.setTitle(NSLocalizedString("LandingCTA", comment: ""), for: .normal) storeButton.setTitleColor(.label, for: .normal) @@ -55,7 +55,7 @@ final class LandingViewController: UIViewController { make.height.equalTo(50) make.centerX.equalToSuperview() } - + disclaimerLabel.accessibilityIdentifier = "DisclaimerLabel" disclaimerLabel.textColor = .lightGray disclaimerLabel.text = NSLocalizedString("LandingDisclaimer", comment: "") @@ -70,13 +70,13 @@ final class LandingViewController: UIViewController { } MParticle.sharedInstance().logScreen("Landing", eventInfo: nil) } - + override func viewDidAppear(_ _: Bool) { if AppDelegate.shouldShowCredsAlert { showCredsAlert() } } - + @objc private func storeButtonAction() { if AppDelegate.shouldShowCredsAlert { showCredsAlert() @@ -91,7 +91,7 @@ final class LandingViewController: UIViewController { window.rootViewController = TabBarController() } } - + private func showCredsAlert() { let keysAlertMessage = UIAlertController(title: NSLocalizedString("AlertKeysMissingTitle", comment: ""), message: NSLocalizedString("AlertKeysMissingMessage", comment: ""), preferredStyle: .alert) let dismissAction = UIAlertAction(title: NSLocalizedString("AlertKeysMissingDismissLabel", comment: ""), style: .default, handler: { _ in diff --git a/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/MyAccountViewController.swift b/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/MyAccountViewController.swift index 15ff789..afcdf59 100644 --- a/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/MyAccountViewController.swift +++ b/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/MyAccountViewController.swift @@ -4,21 +4,21 @@ import mParticle_Apple_SDK final class MyAccountViewController: UIViewController, UITextFieldDelegate { let myAccountLabel = UILabel() - + let myAccountValueTextbox = LabeledTextField() let signInButton = UIButton() - + let signedInLabel = UILabel() let signedInUserLabel = UILabel() let signOutButton = UIButton() - + let disclaimerLabel = UILabel() - + override func viewDidLoad() { MParticle.sharedInstance().logScreen("My Account", eventInfo: nil) - + view.accessibilityLabel = "MyAccountView" - + view.addSubview(myAccountLabel) view.addSubview(myAccountValueTextbox) view.addSubview(signInButton) @@ -27,7 +27,7 @@ final class MyAccountViewController: UIViewController, UITextFieldDelegate { view.addSubview(signOutButton) view.addSubview(disclaimerLabel) toggleVisibility(isSignedIn: false) - + myAccountLabel.accessibilityLabel = "MyAccountTitle" myAccountLabel.text = NSLocalizedString("MyAccountTitle", comment: "") myAccountLabel.font = Utils.boldFont(ofSize: 24) @@ -39,7 +39,7 @@ final class MyAccountViewController: UIViewController, UITextFieldDelegate { make.trailing.equalTo(self.view).offset(-32) make.height.equalTo(24) } - + myAccountValueTextbox.accessibilityLabel = "MyAccountUserIdDefault" myAccountValueTextbox.isUserInteractionEnabled = true myAccountValueTextbox.textBoxField.text = NSLocalizedString("MyAccountUserIdDefault", comment: "") @@ -52,7 +52,7 @@ final class MyAccountViewController: UIViewController, UITextFieldDelegate { make.trailing.equalTo(self.view).offset(-16) make.height.equalTo(63) } - + signInButton.accessibilityLabel = "MyAccountCTAUnselected" signInButton.setTitle(NSLocalizedString("MyAccountCTAUnselected", comment: ""), for: .normal) signInButton.titleLabel?.font = Utils.font(ofSize: 16) @@ -65,7 +65,7 @@ final class MyAccountViewController: UIViewController, UITextFieldDelegate { make.trailing.equalTo(self.view).offset(-16) make.height.equalTo(52) } - + signedInLabel.accessibilityLabel = "MyAccountYouAreSignedInAs" signedInLabel.font = Utils.boldFont(ofSize: 18) signedInLabel.textAlignment = .center @@ -76,7 +76,7 @@ final class MyAccountViewController: UIViewController, UITextFieldDelegate { make.height.equalTo(24) make.centerX.equalToSuperview() } - + signedInUserLabel.accessibilityLabel = "MyAccountSignedInUserLabel" signedInUserLabel.font = Utils.boldFont(ofSize: 18) signedInUserLabel.textAlignment = .center @@ -86,7 +86,7 @@ final class MyAccountViewController: UIViewController, UITextFieldDelegate { make.height.equalTo(20) make.centerX.equalToSuperview() } - + signOutButton.accessibilityLabel = "MyAccountCTASelected" signOutButton.setTitle(NSLocalizedString("MyAccountCTASelected", comment: ""), for: .normal) signOutButton.titleLabel?.font = Utils.font(ofSize: 16) @@ -99,7 +99,7 @@ final class MyAccountViewController: UIViewController, UITextFieldDelegate { make.trailing.equalTo(self.view).offset(-16) make.height.equalTo(52) } - + disclaimerLabel.accessibilityLabel = "DetailDemoOnly" disclaimerLabel.text = NSLocalizedString("DetailDemoOnly", comment: "") disclaimerLabel.textColor = .secondaryLabel @@ -109,7 +109,7 @@ final class MyAccountViewController: UIViewController, UITextFieldDelegate { make.centerX.equalToSuperview() } } - + private func toggleVisibility(isSignedIn: Bool) { if isSignedIn { myAccountValueTextbox.isHidden = true @@ -127,25 +127,25 @@ final class MyAccountViewController: UIViewController, UITextFieldDelegate { signOutButton.isHidden = true } } - + @objc private func signIn() { myAccountValueTextbox.textBoxField.resignFirstResponder() toggleVisibility(isSignedIn: true) let loginRequest = MPIdentityApiRequest.withEmptyUser() loginRequest.email = myAccountValueTextbox.textBoxField.text - + MParticle.sharedInstance().identity.login(loginRequest) { result, error in print("Login request complete - result=\(String(describing: result)) error=\(String(describing: error))") } } - + @objc private func signOut() { toggleVisibility(isSignedIn: false) MParticle.sharedInstance().identity.logout { result, error in print("Logout request complete - result=\(String(describing: result)) error=\(String(describing: error))") } } - + func textFieldShouldReturn(_ textField: UITextField) -> Bool { myAccountValueTextbox.textBoxField.resignFirstResponder() return true diff --git a/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/Product.swift b/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/Product.swift index c887f05..82c8eed 100644 --- a/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/Product.swift +++ b/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/Product.swift @@ -7,11 +7,11 @@ struct Product: Codable { let altText: String let price: Double let variants: Variants - + var image: UIImage? { UIImage(named: imageName) } - + var imageName: String { imageUrl.replacingOccurrences(of: "/products/", with: "").replacingOccurrences(of: ".png", with: "") } diff --git a/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/ProductDetailViewController.swift b/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/ProductDetailViewController.swift index 1f84b01..594b26f 100644 --- a/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/ProductDetailViewController.swift +++ b/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/ProductDetailViewController.swift @@ -3,7 +3,7 @@ import SnapKit import mParticle_Apple_SDK final class ProductDetailViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate { - + let product: Product let titleLabel = UILabel() let priceLabel = UILabel() @@ -16,21 +16,21 @@ final class ProductDetailViewController: UIViewController, UIPickerViewDataSourc var selectedColor: String var selectedSize: String var selectedQuantity: Int - + init(product: Product) { self.product = product self.selectedColor = product.variants.colors[0] self.selectedSize = product.variants.sizes[0] self.selectedQuantity = quantities[0] - + super.init(nibName: nil, bundle: nil) view.backgroundColor = .systemBackground } - + required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } - + override func viewDidLoad() { titleLabel.font = Utils.font(ofSize: 24) view.addSubview(titleLabel) @@ -39,7 +39,7 @@ final class ProductDetailViewController: UIViewController, UIPickerViewDataSourc make.topMargin.equalToSuperview().offset(10) make.centerX.equalToSuperview() } - + priceLabel.font = Utils.font(ofSize: 16) priceLabel.text = "$" + String(format: "%.2f", product.price) view.addSubview(priceLabel) @@ -47,7 +47,7 @@ final class ProductDetailViewController: UIViewController, UIPickerViewDataSourc make.top.equalTo(titleLabel.snp.bottom).offset(5) make.centerX.equalToSuperview() } - + productImageView.image = UIImage(named: product.imageName) productImageView.contentMode = .scaleAspectFill view.addSubview(productImageView) @@ -57,7 +57,7 @@ final class ProductDetailViewController: UIViewController, UIPickerViewDataSourc make.width.equalToSuperview() make.height.equalTo(productImageView.snp.width).multipliedBy(0.77) } - + let pickerStackView = UIStackView() pickerStackView.axis = .horizontal pickerStackView.distribution = .fillProportionally @@ -67,19 +67,19 @@ final class ProductDetailViewController: UIViewController, UIPickerViewDataSourc make.leading.trailing.equalToSuperview() make.height.equalTo(100) } - + colorPicker.dataSource = self colorPicker.delegate = self pickerStackView.addArrangedSubview(colorPicker) - + sizePicker.dataSource = self sizePicker.delegate = self pickerStackView.addArrangedSubview(sizePicker) - + quantityPicker.dataSource = self quantityPicker.delegate = self pickerStackView.addArrangedSubview(quantityPicker) - + addToCartButton.accessibilityIdentifier = "DetailCTA" addToCartButton.setTitle(NSLocalizedString("DetailCTA", comment: ""), for: .normal) addToCartButton.setTitleColor(.label, for: .normal) @@ -99,7 +99,7 @@ final class ProductDetailViewController: UIViewController, UIPickerViewDataSourc event.shouldBeginSession = AppDelegate.eventsBeginSessions MParticle.sharedInstance().logEvent(event) } - + func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView { let titleLabel: UILabel if let label = view as? UILabel { @@ -109,7 +109,7 @@ final class ProductDetailViewController: UIViewController, UIPickerViewDataSourc titleLabel.font = Utils.font(ofSize: 15) titleLabel.textAlignment = .center } - + let titleString: String switch pickerView { case colorPicker: @@ -122,14 +122,14 @@ final class ProductDetailViewController: UIViewController, UIPickerViewDataSourc titleString = "" } titleLabel.text = titleString - + return titleLabel } - + func numberOfComponents(in pickerView: UIPickerView) -> Int { return 1 } - + func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { if pickerView == colorPicker { if product.variants.colors.last == "N/A" { @@ -146,7 +146,7 @@ final class ProductDetailViewController: UIViewController, UIPickerViewDataSourc } return 0 } - + func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) { if pickerView == colorPicker { print("selected color: \(product.variants.colors[row])") @@ -159,18 +159,18 @@ final class ProductDetailViewController: UIViewController, UIPickerViewDataSourc selectedQuantity = quantities[row] } } - + @objc private func productDetailButtonAction() { print("Add to cart tapped - color: \(selectedColor) size: \(selectedSize) quantity: \(selectedQuantity)") - + let cartItem = CartItem(product: product, quantity: selectedQuantity, totalAmount: Double(selectedQuantity) * product.price, color: selectedColor, size: selectedSize) - + let cart = AppDelegate.cart cart.items.append(cartItem) if let tabBarItem = self.tabBarController?.tabBar.items?.last { tabBarItem.badgeValue = "\(cart.items.count)" } - + let mpProduct = MPProduct(name: product.label, sku: product.imageName, quantity: NSNumber(value: selectedQuantity), price: NSNumber(value: product.price)) let attributes = NSMutableDictionary() if selectedColor != "N/A" { @@ -183,7 +183,7 @@ final class ProductDetailViewController: UIViewController, UIPickerViewDataSourc let event = MPCommerceEvent(action: .addToCart, product: mpProduct) event.shouldBeginSession = AppDelegate.eventsBeginSessions MParticle.sharedInstance().logEvent(event) - + navigationController?.popViewController(animated: true) } } diff --git a/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/SceneDelegate.swift b/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/SceneDelegate.swift index c6b98e3..b1344ad 100644 --- a/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/SceneDelegate.swift +++ b/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/SceneDelegate.swift @@ -9,7 +9,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). guard let windowScene = scene as? UIWindowScene else { return } - + // Manually create window to remove need for useless Storyboard file let window = UIWindow(windowScene: windowScene) window.overrideUserInterfaceStyle = .dark // Force app into dark mode diff --git a/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/ShopTableCell.swift b/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/ShopTableCell.swift index 684e17a..6958781 100644 --- a/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/ShopTableCell.swift +++ b/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/ShopTableCell.swift @@ -3,17 +3,17 @@ import SnapKit final class ShopTableCell: UITableViewCell { static let reuseId = "ShopTableCell" - + let productImageView = UIImageView() let productNameLabel = UILabel() - + var product: Product? { didSet { productImageView.image = product?.image productNameLabel.text = product?.label } } - + override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) accessibilityIdentifier = product?.altText @@ -24,7 +24,7 @@ final class ShopTableCell: UITableViewCell { make.leading.trailing.top.equalToSuperview() make.height.equalTo(productImageView.snp.width).multipliedBy(0.77) } - + let nameContainer = UIView() nameContainer.backgroundColor = UIColor(red: 64/255.0, green: 121/255.0, blue: 254/255.0, alpha: 1.0) addSubview(nameContainer) @@ -34,7 +34,7 @@ final class ShopTableCell: UITableViewCell { make.bottom.equalToSuperview().offset(-20) make.height.equalTo(56).priority(.medium) } - + let arrowImageView = UIImageView(image: UIImage(named: "RightArrow")) arrowImageView.accessibilityIdentifier = "ShopCellRightArrowImageView" arrowImageView.contentMode = .scaleAspectFill @@ -44,7 +44,7 @@ final class ShopTableCell: UITableViewCell { make.trailing.equalToSuperview().offset(-22) make.width.height.equalTo(16) } - + productNameLabel.accessibilityIdentifier = "ShopCellProductNameLabel" productNameLabel.textColor = .label productNameLabel.font = Utils.boldFont(ofSize: 20) @@ -55,7 +55,7 @@ final class ShopTableCell: UITableViewCell { make.trailing.equalTo(arrowImageView.snp.leading).offset(-10) } } - + required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } diff --git a/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/ShopViewController.swift b/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/ShopViewController.swift index d63be0b..8272a26 100644 --- a/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/ShopViewController.swift +++ b/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/ShopViewController.swift @@ -3,9 +3,9 @@ import SnapKit import mParticle_Apple_SDK final class ShopViewController: UITableViewController { - + var products = [Product]() - + override func viewDidLoad() { products = readProducts() tableView.accessibilityIdentifier = "ShopTableView" @@ -13,19 +13,19 @@ final class ShopViewController: UITableViewController { tableView.rowHeight = UITableView.automaticDimension tableView.estimatedRowHeight = 350 navigationItem.title = "Shop Higgs" - + edgesForExtendedLayout = [] MParticle.sharedInstance().logScreen("Shop", eventInfo: nil) } - + override func numberOfSections(in tableView: UITableView) -> Int { return 1 } - + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return products.count } - + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let shopTableCell: ShopTableCell if let cell = tableView.dequeueReusableCell(withIdentifier: ShopTableCell.reuseId) as? ShopTableCell { @@ -36,7 +36,7 @@ final class ShopViewController: UITableViewController { shopTableCell.product = products[indexPath.row] return shopTableCell } - + override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { let detailView = ProductDetailViewController(product: products[indexPath.row]) detailView.hidesBottomBarWhenPushed = true @@ -55,7 +55,7 @@ final class ShopViewController: UITableViewController { if let localData = Utils.readLocalFile(forName: "ConfigurationData") { return Utils.parse(jsonData: localData).products } - + return [Product]() } } diff --git a/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/TabBarController.swift b/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/TabBarController.swift index 9da690f..59ff102 100644 --- a/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/TabBarController.swift +++ b/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/TabBarController.swift @@ -1,11 +1,11 @@ import UIKit final class TabBarController: UITabBarController { - + enum TabType: Int, CaseIterable { case shop = 0, myAccount, cart } - + override func viewDidLoad() { super.viewDidLoad() view.accessibilityIdentifier = "TabBarController" @@ -36,5 +36,5 @@ final class TabBarController: UITabBarController { } self.viewControllers = controllers } - + } diff --git a/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/Utils.swift b/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/Utils.swift index 963119c..f77b7c8 100644 --- a/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/Utils.swift +++ b/core-sdk-samples/higgs-shop-sample-app/HiggsShopSampleApp/Utils.swift @@ -11,10 +11,10 @@ final class Utils { } catch { print(error) } - + return nil } - + static func parse(jsonData: Data) -> Configuration { do { let decodedData = try JSONDecoder().decode(Configuration.self, from: jsonData) @@ -22,10 +22,10 @@ final class Utils { } catch { print(error) } - + return Configuration(products: [Product]()) } - + static func font(ofSize size: CGFloat) -> UIFont { guard let customFont = UIFont(name: "Lato-Regular", size: UIFont.labelFontSize) else { print(""" @@ -35,10 +35,10 @@ final class Utils { ) return .systemFont(ofSize: size) } - + return customFont.withSize(size) } - + static func boldFont(ofSize size: CGFloat) -> UIFont { guard let customFont = UIFont(name: "Lato-Bold", size: UIFont.labelFontSize) else { print(""" @@ -48,7 +48,7 @@ final class Utils { ) return .boldSystemFont(ofSize: size) } - + return customFont.withSize(size) } } diff --git a/sideloaded-kit-samples/mp-sideloaded-kit-example/Package.swift b/sideloaded-kit-samples/mp-sideloaded-kit-example/Package.swift index dc1f8a1..dd59c86 100644 --- a/sideloaded-kit-samples/mp-sideloaded-kit-example/Package.swift +++ b/sideloaded-kit-samples/mp-sideloaded-kit-example/Package.swift @@ -9,19 +9,19 @@ let package = Package( products: [ .library( name: "mp-sideloaded-kit-example", - targets: ["mp-sideloaded-kit-example"]), + targets: ["mp-sideloaded-kit-example"]) ], dependencies: [ .package(name: "mParticle-Apple-SDK", url: "https://github.com/mParticle/mparticle-apple-sdk", - .upToNextMajor(from: "8.0.0")), + .upToNextMajor(from: "8.0.0")) ], targets: [ .target( name: "mp-sideloaded-kit-example", dependencies: [ - .byName(name: "mParticle-Apple-SDK"), + .byName(name: "mParticle-Apple-SDK") ], - path: "src"), + path: "src") ] ) diff --git a/sideloaded-kit-samples/mp-sideloaded-kit-example/src/ConsoleLoggingKit.swift b/sideloaded-kit-samples/mp-sideloaded-kit-example/src/ConsoleLoggingKit.swift index 7c64740..26addc5 100644 --- a/sideloaded-kit-samples/mp-sideloaded-kit-example/src/ConsoleLoggingKit.swift +++ b/sideloaded-kit-samples/mp-sideloaded-kit-example/src/ConsoleLoggingKit.swift @@ -11,34 +11,34 @@ import mParticle_Apple_SDK @objc public class ConsoleLoggingKit: NSObject, MPKitProtocol { // Not used in sideloaded kits public static func kitCode() -> NSNumber { -1 } - + // Must be true to receive callbacks, can set to true later after any needed initialization is performed public var started: Bool = true - + public var sideloadedKitCode: NSNumber = 0 - + public var kitApi: MPKitAPI? - - public func didFinishLaunching(withConfiguration configuration: [AnyHashable : Any]) -> MPKitExecStatus { + + public func didFinishLaunching(withConfiguration configuration: [AnyHashable: Any]) -> MPKitExecStatus { print("[ConsoleLoggingKit] didFinishLaunching, configuration: \(configuration), kitApi: \(String(describing: kitApi))") return MPKitExecStatus(sdkCode: sideloadedKitCode, returnCode: .success) } - + public func didBecomeActive() -> MPKitExecStatus { print("[ConsoleLoggingKit] didBecomeActive") return MPKitExecStatus(sdkCode: sideloadedKitCode, returnCode: .success) } - + public func beginSession() -> MPKitExecStatus { print("[ConsoleLoggingKit] beginSession") return MPKitExecStatus(sdkCode: sideloadedKitCode, returnCode: .success) } - + public func endSession() -> MPKitExecStatus { print("[ConsoleLoggingKit] endSession") return MPKitExecStatus(sdkCode: sideloadedKitCode, returnCode: .success) } - + public func logBaseEvent(_ event: MPBaseEvent) -> MPKitExecStatus { print("[ConsoleLoggingKit] logBaseEvent") return MPKitExecStatus(sdkCode: sideloadedKitCode, returnCode: .success) From 1f2ec694021a0651ff0f96d87e1e9476b3ea3c03 Mon Sep 17 00:00:00 2001 From: Ben Baron Date: Tue, 15 Oct 2024 11:09:25 -0500 Subject: [PATCH 4/4] Fix CI --- .github/workflows/higgs-shop-sample-app-pull-request.yml | 8 ++++---- .github/workflows/higgs-shop-sample-app-release.yml | 4 ++-- .github/workflows/sync-higgs-shop-data-plan.yml | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/higgs-shop-sample-app-pull-request.yml b/.github/workflows/higgs-shop-sample-app-pull-request.yml index d9c008f..e1d37ae 100644 --- a/.github/workflows/higgs-shop-sample-app-pull-request.yml +++ b/.github/workflows/higgs-shop-sample-app-pull-request.yml @@ -25,7 +25,7 @@ jobs: uses: actions/checkout@v4 - name: Run UI tests - run: xcodebuild test -project HiggsShopSampleApp.xcodeproj -destination "platform=iOS Simulator,name=iPhone 12,OS=latest" -scheme HiggsShopSampleApp + run: xcodebuild test -project HiggsShopSampleApp.xcodeproj -destination "platform=iOS Simulator,name=iPhone 15,OS=latest" -scheme HiggsShopSampleApp run-tests-with-thread-sanitizer: runs-on: macos-latest @@ -34,7 +34,7 @@ jobs: uses: actions/checkout@v4 - name: Run tests with thread sanitizer - run: xcodebuild test -project HiggsShopSampleApp.xcodeproj -destination "platform=iOS Simulator,name=iPhone 12,OS=latest" -scheme HiggsShopSampleApp -enableThreadSanitizer YES + run: xcodebuild test -project HiggsShopSampleApp.xcodeproj -destination "platform=iOS Simulator,name=iPhone 15,OS=latest" -scheme HiggsShopSampleApp -enableThreadSanitizer YES run-tests-with-address-sanitizer: @@ -44,7 +44,7 @@ jobs: uses: actions/checkout@v4 - name: Run tests with address sanitizer - run: xcodebuild test -project HiggsShopSampleApp.xcodeproj -destination "platform=iOS Simulator,name=iPhone 12,OS=latest" -scheme HiggsShopSampleApp -enableAddressSanitizer YES + run: xcodebuild test -project HiggsShopSampleApp.xcodeproj -destination "platform=iOS Simulator,name=iPhone 15,OS=latest" -scheme HiggsShopSampleApp -enableAddressSanitizer YES run-analyzer: runs-on: macos-latest @@ -53,4 +53,4 @@ jobs: uses: actions/checkout@v4 - name: Run static analyzer - run: xcodebuild analyze -project HiggsShopSampleApp.xcodeproj -scheme HiggsShopSampleApp -destination "platform=iOS Simulator,name=iPhone 12,OS=latest" + run: xcodebuild analyze -project HiggsShopSampleApp.xcodeproj -scheme HiggsShopSampleApp -destination "platform=iOS Simulator,name=iPhone 15,OS=latest" diff --git a/.github/workflows/higgs-shop-sample-app-release.yml b/.github/workflows/higgs-shop-sample-app-release.yml index 1a3b835..ad75e34 100644 --- a/.github/workflows/higgs-shop-sample-app-release.yml +++ b/.github/workflows/higgs-shop-sample-app-release.yml @@ -18,7 +18,7 @@ jobs: runs-on: macOS-latest steps: - name: Git checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Branch name run: | @@ -43,7 +43,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Release --dry-run if: ${{ github.event.inputs.dryRun == 'true'}} diff --git a/.github/workflows/sync-higgs-shop-data-plan.yml b/.github/workflows/sync-higgs-shop-data-plan.yml index b469128..f1b1dfd 100644 --- a/.github/workflows/sync-higgs-shop-data-plan.yml +++ b/.github/workflows/sync-higgs-shop-data-plan.yml @@ -26,7 +26,7 @@ jobs: GIT_COMMITTER_EMAIL: developers@mparticle.com steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: ref: development