diff --git a/litewallet/AppDelegate.swift b/litewallet/AppDelegate.swift index c11820980..c4c10e12c 100644 --- a/litewallet/AppDelegate.swift +++ b/litewallet/AppDelegate.swift @@ -9,7 +9,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? let applicationController = ApplicationController() // FIXME: - Waiting for Pusher to respond: https://github.com/pusher/push-notifications-swift/issues/187 - // let pushNotifications = PushNotifications.shared + let pushNotifications = PushNotifications.shared func application(_ application: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { @@ -37,7 +37,24 @@ class AppDelegate: UIResponder, UIApplicationDelegate { Bundle.setLanguage(UserDefaults.selectedLanguage) - // "bbac5210-989c-49d5-a336-ae1eaf81e586" + // Pusher + pushNotifications.start(instanceId: "bbac5210-989c-49d5-a336-ae1eaf81e586") + pushNotifications.registerForRemoteNotifications() + + let generaliOSInterest = "general-ios" + let debugGeneraliOSInterest = "debug-general-ios" + + try? pushNotifications + .addDeviceInterest(interest: generaliOSInterest) + try? pushNotifications + .addDeviceInterest(interest: debugGeneraliOSInterest) + + let interests = pushNotifications.getDeviceInterests()?.joined(separator: "|") ?? "" + let device = UIDevice.current.identifierForVendor?.uuidString ?? "ID" + let interestesDict: [String: String] = ["device_id": device, + "pusher_interests": interests] + + LWAnalytics.logEventWithParameters(itemName: ._20231202_RIGI, properties: interestesDict) return true } @@ -81,6 +98,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate { return true } + func application(_: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { + pushNotifications.registerDeviceToken(deviceToken) + } + + func application(_: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler _: @escaping (UIBackgroundFetchResult) -> Void) { + pushNotifications.handleNotification(userInfo: userInfo) + } + /// Sets the correct Google Services plist file private func setFirebaseConfiguration() { // Load a Firebase debug config file. diff --git a/litewallet/src/Constants/Constants.swift b/litewallet/src/Constants/Constants.swift index a01f4d0d0..9de142a2e 100644 --- a/litewallet/src/Constants/Constants.swift +++ b/litewallet/src/Constants/Constants.swift @@ -138,6 +138,9 @@ enum CustomEvent: String { /// User Tapped on UD Image case _20220822_UTOU = "user_tapped_on_ud" + + /// User registered Pusher interest + case _20231202_RIGI = "registered_ios_general_interest" } struct FoundationSupport { diff --git a/litewallet/src/SimpleRedux/Actions.swift b/litewallet/src/SimpleRedux/Actions.swift index 015b4b0df..82315a16f 100644 --- a/litewallet/src/SimpleRedux/Actions.swift +++ b/litewallet/src/SimpleRedux/Actions.swift @@ -209,15 +209,6 @@ enum MaxDigits { } } -enum PushNotifications { - struct setIsEnabled: Action { - let reduce: Reducer - init(_ isEnabled: Bool) { - reduce = { $0.clone(isPushNotificationsEnabled: isEnabled) } - } - } -} - enum biometricsActions { struct setIsPrompting: Action { let reduce: Reducer diff --git a/litewallet/src/ViewControllers/PushNotificationsViewController.swift b/litewallet/src/ViewControllers/PushNotificationsViewController.swift deleted file mode 100644 index dcd429698..000000000 --- a/litewallet/src/ViewControllers/PushNotificationsViewController.swift +++ /dev/null @@ -1,78 +0,0 @@ -import UIKit - -class PushNotificationsViewController: UIViewController { - init(store: Store) { - self.store = store - super.init(nibName: nil, bundle: nil) - } - - private let store: Store - private let titleLabel = UILabel(font: .customBold(size: 26.0), color: .darkText) - private let body = UILabel.wrapping(font: .customBody(size: 16.0), color: .darkText) - private let label = UILabel(font: .customBold(size: 16.0), color: .darkText) - private let toggle = GradientSwitch() - private let separator = UIView(color: .secondaryShadow) - - override func viewDidLoad() { - addSubviews() - addConstraints() - setData() - } - - private func addSubviews() { - view.addSubview(titleLabel) - view.addSubview(body) - view.addSubview(label) - view.addSubview(toggle) - view.addSubview(separator) - } - - private func addConstraints() { - titleLabel.constrain([ - titleLabel.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: C.padding[2]), - titleLabel.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: C.padding[2]), - ]) - body.constrain([ - body.leadingAnchor.constraint(equalTo: titleLabel.leadingAnchor), - body.topAnchor.constraint(equalTo: titleLabel.bottomAnchor, constant: C.padding[1]), - body.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -C.padding[2]), - ]) - label.constrain([ - label.leadingAnchor.constraint(equalTo: body.leadingAnchor), - label.topAnchor.constraint(equalTo: body.bottomAnchor, constant: C.padding[3]), - ]) - toggle.constrain([ - toggle.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -C.padding[2]), - toggle.centerYAnchor.constraint(equalTo: label.centerYAnchor), - ]) - separator.constrain([ - separator.leadingAnchor.constraint(equalTo: label.leadingAnchor), - separator.topAnchor.constraint(equalTo: toggle.bottomAnchor, constant: C.padding[2]), - separator.trailingAnchor.constraint(equalTo: toggle.trailingAnchor), - separator.heightAnchor.constraint(equalToConstant: 1.0), - ]) - } - - private func setData() { - view.backgroundColor = .whiteTint - titleLabel.text = S.PushNotifications.title.localize() - body.text = S.PushNotifications.body.localize() - label.text = S.PushNotifications.label.localize() - - toggle.isOn = store.state.isPushNotificationsEnabled - toggle.sendActions(for: .valueChanged) - - toggle.valueChanged = { [weak self] in - guard let myself = self else { return } - myself.store.perform(action: PushNotifications.setIsEnabled(myself.toggle.isOn)) - if myself.toggle.isOn { - myself.store.trigger(name: .registerForPushNotificationToken) - } - } - } - - @available(*, unavailable) - required init?(coder _: NSCoder) { - fatalError("init(coder:) has not been implemented") - } -}