Skip to content

Commit

Permalink
fix(ios): fire resume/pause events if no cordova plugins installed (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored Apr 22, 2021
1 parent dd26a98 commit 0105f7a
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions ios/Capacitor/Capacitor/CapacitorBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ internal class CapacitorBridge: NSObject, CAPBridgeProtocol {

// Background dispatch queue for plugin calls
var dispatchQueue = DispatchQueue(label: "bridge")
// Array of block based observers
var observers: [NSObjectProtocol] = []

// MARK: - CAPBridgeProtocol: Deprecated

Expand Down Expand Up @@ -189,14 +191,17 @@ internal class CapacitorBridge: NSObject, CAPBridgeProtocol {
exportCoreJS(localUrl: configuration.localURL.absoluteString)
registerPlugins()
setupCordovaCompatibility()
NotificationCenter.default.addObserver(forName: type(of: self).tmpVCAppeared.name, object: .none, queue: .none) { [weak self] _ in
observers.append(NotificationCenter.default.addObserver(forName: type(of: self).tmpVCAppeared.name, object: .none, queue: .none) { [weak self] _ in
self?.tmpWindow = nil
}
})
}

deinit {
// the message handler needs to removed to avoid any retain cycles
webViewDelegationHandler.cleanUp()
for observer in observers {
NotificationCenter.default.removeObserver(observer)
}
}

// MARK: - Plugins
Expand All @@ -220,6 +225,13 @@ internal class CapacitorBridge: NSObject, CAPBridgeProtocol {
if injectCordovaFiles {
exportCordovaJS()
registerCordovaPlugins()
} else {
observers.append(NotificationCenter.default.addObserver(forName: UIApplication.didBecomeActiveNotification, object: nil, queue: OperationQueue.main) { [weak self] (_) in
self?.triggerDocumentJSEvent(eventName: "resume")
})
observers.append(NotificationCenter.default.addObserver(forName: UIApplication.willResignActiveNotification, object: nil, queue: OperationQueue.main) { [weak self] (_) in
self?.triggerDocumentJSEvent(eventName: "pause")
})
}
}

Expand Down

0 comments on commit 0105f7a

Please sign in to comment.