Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Call to objc_getClassList in CapacitorBridge causes crash if presenting Portals view based on Apple SDK availability #7116

Closed
pbush25 opened this issue Dec 5, 2023 · 3 comments

Comments

@pbush25
Copy link

pbush25 commented Dec 5, 2023

Bug Report

We present a portal's view that depending on OS availability creates a Live Activity. Because Live Activities are only supported on iOS 16.2+, this is done with if #available(iOS 16.2, *) checks.

In order for this to work we have two different versions of our native Portal's view wrapper. One for iOS 16 and one for iOS 16.2+. The one for iOS 16.2+ is prefixed with @available(iOS 16.2, *).

In other native code, this combo of @available and if #available() checks is sufficient to prevent code from being included that should not be based on the OS version.

However, when launching our Portal's view we encounter a crash with the following stack trace.
image (1)

The crash is in CapacitorBridge:279 specifically on the call to objs_getClassList.

I did some research, and there is an issue with this exact same problem in the Swift project, with Swift contributors suggesting using this API is neither efficient, nor safe in the event of including classes based on #available checks. Please see this link: swiftlang/swift#61215

Platform(s)

'IonicPortals', '~> 0.7.0'
Capacitor 4.6.2
CapacitorCordova 4.6.2

iOS (any version) where a developer might choose to include use of ios-specific APIs that are properly hidden behind @available and #available() checks

Current Behavior

In the situation that a class is only included based on Apple SDK availability, the App will crash when presenting a Portal's view.

Expected Behavior

Presenting a Portal's view should not crash the app, as code that is not specific to the user's OS should not be tried to be accessed by legacy obj-c API.

Other Technical Details

Xcode 15.0

npm --version output:
10.2.4
node --version output:
v18.18.2
pod --version output (iOS issues only):
1.14.2

Additional Context

swiftlang/swift#61215
image (1)

@Steven0351
Copy link
Member

Steven0351 commented Dec 5, 2023

I replied to the issue you opened in ionic-team/ionic-portals#255. This is a known issue that can impact Portals applications with applications that contain non-trivial amounts of native code. You are on an old version of Portals that still allows for plugin auto-registration to occur, but it can be disabled by setting the Portal pluginRegistrationMode to .manual([]). Version 0.8.0 of Portals removed the option for auto-registration altogether and this crash will not occur because there is no codepath that will execute objc_getClassList. The latest version of Portals for iOS is 0.9.0.

@markemer
Copy link
Member

Fixed for Capacitor 6 in #7187

Copy link

ionitron-bot bot commented Feb 18, 2024

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Feb 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants