Skip to content

Commit

Permalink
chore: address review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
rnr committed Feb 8, 2024
1 parent 27c2553 commit 2b3f9a5
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 64 deletions.
56 changes: 27 additions & 29 deletions OpenEdX/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,33 +74,33 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
_ app: UIApplication,
open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]
) -> Bool {
if let config = Container.shared.resolve(ConfigProtocol.self) {
if let deepLinkManager = Container.shared.resolve(DeepLinkManager.self),
deepLinkManager.serviceEnabled {
if deepLinkManager.handledURLWith(app: app, open: url, options: options) {
return true
}
}
guard let config = Container.shared.resolve(ConfigProtocol.self) else { return false }

if config.facebook.enabled {
ApplicationDelegate.shared.application(
app,
open: url,
sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
annotation: options[UIApplication.OpenURLOptionsKey.annotation]
)
if let deepLinkManager = Container.shared.resolve(DeepLinkManager.self),
deepLinkManager.anyServiceEnabled {
if deepLinkManager.handledURLWith(app: app, open: url, options: options) {
return true
}
}

if config.google.enabled {
return GIDSignIn.sharedInstance.handle(url)
}
if config.facebook.enabled {
ApplicationDelegate.shared.application(
app,
open: url,
sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
annotation: options[UIApplication.OpenURLOptionsKey.annotation]
)
}

if config.microsoft.enabled {
return MSALPublicClientApplication.handleMSALResponse(
url,
sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String
)
}
if config.google.enabled {
return GIDSignIn.sharedInstance.handle(url)
}

if config.microsoft.enabled {
return MSALPublicClientApplication.handleMSALResponse(
url,
sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String
)
}

return false
Expand Down Expand Up @@ -139,14 +139,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

// Push Notifications
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
if let pushManager = Container.shared.resolve(PushNotificationsManager.self) {
pushManager.didRegisterForRemoteNotificationsWithDeviceToken(deviceToken: deviceToken)
}
guard let pushManager = Container.shared.resolve(PushNotificationsManager.self) else { return }
pushManager.didRegisterForRemoteNotificationsWithDeviceToken(deviceToken: deviceToken)
}
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
if let pushManager = Container.shared.resolve(PushNotificationsManager.self) {
pushManager.didFailToRegisterForRemoteNotificationsWithError(error: error)
}
guard let pushManager = Container.shared.resolve(PushNotificationsManager.self) else { return }
pushManager.didFailToRegisterForRemoteNotificationsWithError(error: error)
}
func application(
_ application: UIApplication,
Expand Down
33 changes: 17 additions & 16 deletions OpenEdX/Managers/DeepLinkManager/DeepLinkManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,30 @@ public protocol DeepLinkService {
}

class DeepLinkManager {
private var service: DeepLinkService?
private var services: [DeepLinkService] = []

// Init manager
public init(config: ConfigProtocol) {
self.service = self.serviceFor(config: config)
services = servicesFor(config: config)
}

private func serviceFor(config: ConfigProtocol) -> DeepLinkService? {
// init deep link service
private func servicesFor(config: ConfigProtocol) -> [DeepLinkService] {
var deepServices: [DeepLinkService] = []
// init deep link services
if config.branch.enabled {
return BranchService()
deepServices.append(BranchService())
}
return nil
return deepServices
}

// check if service is added (means enabled)
var serviceEnabled: Bool {
service != nil
// check if any service is added (means enabled)
var anyServiceEnabled: Bool {
services.count > 0
}

// Configure services
func configureDeepLinkService(launchOptions: [UIApplication.LaunchOptionsKey: Any]?) {
if let service = service {
for service in services {
service.configureWith(launchOptions: launchOptions)
}
}
Expand All @@ -48,22 +49,22 @@ class DeepLinkManager {
open url: URL,
options: [UIApplication.OpenURLOptionsKey: Any] = [:]
) -> Bool {
if let service = service {
return service.handledURLWith(app: app, open: url, options: options)
for service in services where service.handledURLWith(app: app, open: url, options: options) {
return true
}
return false
}

// This method process push notification with the link object
func processNotification(with link: PushLink) {
if let service = service {
// This method do redirect with link from push notification
func processLinkFromNotification(_ link: PushLink) {
if anyServiceEnabled {
// redirect if possible
}
}

// This method process the deep link with response parameters
func processDeepLink(with params: [String: Any]) {
if let service = service {
if anyServiceEnabled {
// redirect if possible
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
import Foundation

class BrazeProvider: PushNotificationsProvider {
func registerWithDeviceToken(deviceToken: Data) {
func didRegisterWithDeviceToken(deviceToken: Data) {

}

func didFailToRegisterForRemoteNotificationsWithError(error: Error) {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
import Foundation

class FCMProvider: PushNotificationsProvider {
func registerWithDeviceToken(deviceToken: Data) {
func didRegisterWithDeviceToken(deviceToken: Data) {

}

func didFailToRegisterForRemoteNotificationsWithError(error: Error) {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import UIKit
import Swinject

public protocol PushNotificationsProvider {
func registerWithDeviceToken(deviceToken: Data)
func didRegisterWithDeviceToken(deviceToken: Data)
func didFailToRegisterForRemoteNotificationsWithError(error: Error)
}

Expand All @@ -22,11 +22,12 @@ protocol PushNotificationsListener {

extension PushNotificationsListener {
func didReceiveRemoteNotification(userInfo: [AnyHashable: Any]) {
guard let dictionary = userInfo as? [String: Any], shouldListenNotification(userinfo: userInfo) else { return }
let link = PushLink(dictionary: dictionary)
if let deepLinkManager = Container.shared.resolve(DeepLinkManager.self) {
deepLinkManager.processNotification(with: link)
}
guard let dictionary = userInfo as? [String: Any],
shouldListenNotification(userinfo: userInfo),
let deepLinkManager = Container.shared.resolve(DeepLinkManager.self)
else { return }
let link = PushLink(dictionary: dictionary)
deepLinkManager.processLinkFromNotification(link)
}
}

Expand All @@ -36,30 +37,30 @@ class PushNotificationsManager {

// Init manager
public init(config: ConfigProtocol) {
self.providers = self.providersFor(config: config)
self.listeners = self.listenersFor(config: config)
providers = providersFor(config: config)
listeners = listenersFor(config: config)
}

private func providersFor(config: ConfigProtocol) -> [PushNotificationsProvider] {
var rProviders: [PushNotificationsProvider] = []
var pushProviders: [PushNotificationsProvider] = []
if config.firebase.cloudMessagingEnabled {
rProviders.append(FCMProvider())
pushProviders.append(FCMProvider())
}
if config.braze.pushNotificationsEnabled {
rProviders.append(BrazeProvider())
pushProviders.append(BrazeProvider())
}
return rProviders
return pushProviders
}

private func listenersFor(config: ConfigProtocol) -> [PushNotificationsListener] {
var rListeners: [PushNotificationsListener] = []
var pushListeners: [PushNotificationsListener] = []
if config.firebase.cloudMessagingEnabled {
rListeners.append(FCMListener())
pushListeners.append(FCMListener())
}
if config.braze.pushNotificationsEnabled {
rListeners.append(BrazeListener())
pushListeners.append(BrazeListener())
}
return rListeners
return pushListeners
}

// Register for push notifications
Expand All @@ -80,7 +81,7 @@ class PushNotificationsManager {
// Proccess functions from app delegate
public func didRegisterForRemoteNotificationsWithDeviceToken(deviceToken: Data) {
for provider in providers {
provider.registerWithDeviceToken(deviceToken: deviceToken)
provider.didRegisterWithDeviceToken(deviceToken: deviceToken)
}
}
public func didFailToRegisterForRemoteNotificationsWithError(error: Error) {
Expand Down

0 comments on commit 2b3f9a5

Please sign in to comment.