Bug Report
On iOS, Toast notification appears under a new window if you dynamically create a new one
Plugin(s)
Toast
Capacitor Version
💊 Capacitor Doctor 💊
Latest Dependencies:
@capacitor/cli: 8.3.4
@capacitor/core: 8.3.4
@capacitor/android: 8.3.4
@capacitor/ios: 8.3.4
Installed Dependencies:
@capacitor/cli: 8.3.4
@capacitor/core: 8.3.4
@capacitor/android: 8.3.4
@capacitor/ios: 8.3.4
[success] iOS looking great! 👌
[success] Android looking great! 👌
Platform(s)
iOS
Current Behavior
- Load root page.
- Show Toast
- Toast Appears. (GOOD)
- Load InAppBrowser plugin
- Show Toast.
- Toast does not appear (BUG)
Expected Behavior
- Load root page.
- Show Toast
- Toast Appears.
- Load InAppBrowser webpage
- Show Toast.
- Toast SHOULD also appear.
Code Reproduction
- Load root page.
- Show Toast
- Toast Appears. (GOOD)
- Load InAppBrowser plugin OR any custom plugin that occupies the entire screen.
- Show Toast.
- Toast does not appear (BUG)
Other Technical Details
It seems that the bug was caused by this line of code:
viewController.view.addSubview(label)
I maneged to fix it by adding extension UIApplication on Toast.swift:
extension UIApplication {
var topWindow: UIWindow? {
if #available(iOS 15.0, *){
return connectedScenes
.compactMap { $0 as? UIWindowScene }
.flatMap{ $0.windows }
.first{ $0.isKeyWindow }
}else{
return keyWindow
}
}
}
and editing @objc public class Toast: NSObject
...
DispatchQueue.main.async {
// define the extension I created
guard let window = UIApplication.shared.topWindow else { return }
...
// replace: viewController.view.addSubview(label)
window.addSubview(label);
....
}
Code above fixed my issue. Haven't generally tested on all other scenario.
Additional Context
Bug only happens on iOS, unable to replicate on Android or Web
Bug Report
On iOS, Toast notification appears under a new window if you dynamically create a new one
Plugin(s)
Toast
Capacitor Version
Platform(s)
iOS
Current Behavior
Expected Behavior
Code Reproduction
Other Technical Details
It seems that the bug was caused by this line of code:
I maneged to fix it by adding extension UIApplication on Toast.swift:
and editing
@objc public class Toast: NSObjectCode above fixed my issue. Haven't generally tested on all other scenario.
Additional Context
Bug only happens on iOS, unable to replicate on Android or Web