skip to Main Content

I have the following code in Objective-C:

if (@available(iOS 13.0, tvOS 13.0, *)) {
    indicator.indicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleLarge;
} else {
    indicator.indicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
}

But this is producing an error.

'UIActivityIndicatorViewStyleWhiteLarge' is unavailable: not available on xrOS

I think I need that first conditional to get run so it doesn’t even try to access UIActivityIndicatorViewStyleWhiteLarge.

But when I change the line to if (@available(iOS 13.0, tvOS 13.0, visionOS 1.0, *)). I get the following error:

Unrecognized platform name visionOS

I also tried changing it to xrOS 1.0 (since I heard that some internal usages had it as xrOS for a while. And while I don’t get the second compiler error, it does still say it’s unavailable.

Any ideas on how to fix this?

2

Answers


  1. Sadly Objective-C is terrible when it comes to @available. If you were to write that same logic in Swift you would not get the deprecation warning. I don’t know why Objective-C doesn’t work better in this regard.

    As you’ve seen, adding xrOS 1.0 to the @available doesn’t eliminate the deprecation warning despite the fact that at runtime, the else will not be executed due to the @available. So while it works at runtime, the compiler needlessly complains about a situation that it should not.

    In my own experience, the only solution is to make use of compiler directives. While my experience is with Mac Catalyst and not visionOS, the issue is the same.

    You need to write ugly code similar to the following:

    #if TARGET_OS_XROS // I'm guessing on the XROS - use code completion to see your options
        indicator.indicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleLarge;
    #else
        if (@available(iOS 13.0, tvOS 13.0, *)) {
            indicator.indicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleLarge;
        } else {
            indicator.indicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
        }
    #endif
    

    The bad part of this is the code duplication. Your only other options are converting to Swift or accepting the deprecation warning.

    Login or Signup to reply.
  2. Use TARGET_OS_XR to distinguish RealityKit only targets:

    #if TARGET_OS_XR
    
    #else
    
    #endif // TARGET_OS_XR
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search