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

Make 4.4.0 compile on tvOS #125

Open
etiennelab opened this issue Jul 4, 2024 · 2 comments
Open

Make 4.4.0 compile on tvOS #125

etiennelab opened this issue Jul 4, 2024 · 2 comments
Assignees

Comments

@etiennelab
Copy link

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch react-native-purchasely@4.4.0 for the project I'm working on.

In our react-native project, we use the tv fork of react-native (react-native-tvos) to handle Android TV and tvOS since it's not maintained anymore in the main repo.
We also use your product Purchasely, and its react native lib. In the podspec, it indicates it's available in tvos (s.tvos.deployment_target = '11.0' ), but in the last version, there's an #available check only for iOS but not tvOS.
This PR fixes the build issue for tvOS.

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-purchasely/ios/PurchaselyView.swift b/node_modules/react-native-purchasely/ios/PurchaselyView.swift
index 16d9a38..9a93e6b 100644
--- a/node_modules/react-native-purchasely/ios/PurchaselyView.swift
+++ b/node_modules/react-native-purchasely/ios/PurchaselyView.swift
@@ -43,12 +43,20 @@ class PurchaselyView: UIView {
     let view = _controller?.view ?? UIView()
     self.addSubview(view)
 
-      var statusBarHeight: CGFloat = 0.0
-      if #available(iOS 13.0, *) {
-          statusBarHeight = UIApplication.shared.windows.first?.windowScene?.statusBarManager?.statusBarFrame.height ?? 0.0
-      } else {
-          statusBarHeight = UIApplication.shared.statusBarFrame.height
-      }
+    var statusBarHeight: CGFloat = 0.0
+#if TARGET_OS_IOS
+    if #available(iOS 13.0, *) {
+        statusBarHeight = UIApplication.shared.windows.first?.windowScene?.statusBarManager?.statusBarFrame.height ?? 0.0
+    } else {
+        statusBarHeight = UIApplication.shared.statusBarFrame.height
+    }
+#elseif TARGET_OS_TV
+    if #available(tvOS 13.0, *) {
+        statusBarHeight = UIApplication.shared.windows.first?.windowScene?.statusBarManager?.statusBarFrame.height ?? 0.0
+    } else {
+        statusBarHeight = UIApplication.shared.statusBarFrame.height
+    }
+#endif
     
     view.translatesAutoresizingMaskIntoConstraints = false
     NSLayoutConstraint.activate([

This issue body was partially generated by patch-package.

@EPIKorial EPIKorial self-assigned this Jul 5, 2024
@EPIKorial
Copy link
Contributor

Hello @etiennelab,

Thank you so much for reaching out to us about this issue. We greatly appreciate and value our customers' feedback!

I apologize for the inconvenience you encountered, but it looks like you managed to solve it effectively—congratulations!

Your suggested fix is indeed relevant. May I suggest the following adjustment ? (Since the code is basically the same)

var statusBarHeight: CGFloat = 0.0
if #available(iOS 13.0, tvOS 13.0, *) {
          statusBarHeight = UIApplication.shared.windows.first?.windowScene?.statusBarManager?.statusBarFrame.height ?? 0.0
      } else {
          statusBarHeight = UIApplication.shared.statusBarFrame.height
      }

Would it work the same for you?

We will integrate this fix into our next release, which should arrive soon. We will notify our customers as soon as it goes live, so stay tuned.

Thanks again for your feedback and assistance with this matter.

Best regards,
Florian

@etiennelab
Copy link
Author

Thanks @EPIKorial, of course it is way more concise and readable !

Looking forward to the next release,

Etienne

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants