.glassEffect(_in:) crushing on iOS 26 public beta.

In one of my apps, i am using .glassEffect(_:In) to add glass effect on various elements. The app always crushes when a UI element with glassEffect(_in:) modifier is being rendered. This only happens on device running iOS 26 public beta. I know this for certain because I connected the particular device to xcode and run the app on the device. When i comment out the glassEffect modifier, app doesn't crush.

Is it possible to check particular realeases with #available? If not, how should something like this be handled. Also how do i handle such os level erros without the app crushing. Thanks.

Do you mean 'crashing'?

Which version is 'iOS public beta'? Is it iOS 26.2 beta? Or is this the public beta before iOS 26 was first released in September?

What code are you using, and what is the crash? You say you're using .glassEffect(_in:) but you don't give any actual values.

Yeah, it will be a really big surprise if using .glassEffect(_:in:) triggers a crash in the latest iOS. So as @darkpaw said, providing more details about your issue will help clarify.

Regarding #available, you can definitely use it to check the OS version. The following code behaves differently on iOS 26.1 and later:

if #available(iOS 26.1, *) {
	print("iOS 26.1 and later")
} else {
	print("Before iOS 26.1")
}

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

I am using a view modifier like this:

struct GlassEffectViewModifier: ViewModifier {

    var shape: any InsettableShape = .capsule

    var fallBack: Material = .thin

    func body(content: Content) -> some View {
        if #available(iOS 26.0, *) {
            content
                .glassEffect(.regular, in: shape)
        } else {
            content
                .background(fallBack, in: .capsule)
        }
    }
}

extension View {
     public func withGlassEffect(
        in shape: some InsettableShape = .capsule,
        fallback: Material = .thin
     ) -> some View {
        modifier(
            GlassEffectWithShapeViewModifier(shape: shape, fallBack: fallback)
        )
    }
}

It always crashes on the .glassEffect(.regular, in: shape) line. If i comment it out or use a different modifier, it doesn't crash.

You added a comment to my post saying:

The device is running the public beta before iOS 26 was officially released in september

You shouldn't be running the public beta from before iOS 26 was released. That version is out of date.

Does your code work on the currently-released version of iOS, which is 26.1?

My main concern now is, isn't there any proper way to handle such errors or excetions so that app doesn't just terminate without any message to user?

Firstly, please ignore the pre-release Public Beta; it's irrelevant. The fact that a friend of yours is running it is irrelevant. It is not a supported version of iOS, and you should not be developing against it.

Think about it... Apple might release ten betas of iOS 27; are you going to write your apps so that they run on all ten betas, even though no one will be running those betas anymore?

Your friend should not be running the Public Beta. It is not supported, and you should not support it either.

Secondly, the way to correctly make sure your app doesn't crash on different versions of iOS is to test your app. Xcode allows you to use multiple Simulators which will let you catch most issues.

Also, you can use code such as if #available(iOS 26.0, *) to conditionally run code that applies only if that version of iOS is available on the device. If it isn't, you run some other code. I do this all the time. I have a function like this:

func olderiOS() -> Bool {
    if #available(iOS 26.0, *) {
        return false
    }
    return true
}

// Create a global var to use it so we don't keep running the check:
let isOlderiOS: Bool = olderiOS()

I use it for inline checks, such as: .padding(.top, (isOlderiOS ? 10 : 5) where you can't use if #available().

Finally, you can apply conditional modifiers to code. Something like this:

public struct Additional<Content> {
	public let content: Content
	public init(_ content: Content) {
		self.content = content
	}
}

extension View {
	var additional: Additional<Self> { Additional(self) }
}

extension Additional where Content: View {
	@ViewBuilder func presentationDetents_before_iOS18_0(height: CGFloat) -> some View {
		if #available(iOS 18.0, *) {
			content
				.presentationDetents([.height(height)])

		} else {
			content
		}
	}
}

I've created the presentationDetents_before_iOS18_0 modifier because you can't use the .presentationDetents modifier before iOS 18, so this function applies it if iOS 18.0+ is available, and doesn't if we're on iOS 17 or below. I use it like this:

.sheet(isPresented: $showSheet) {
	ChooseImageSheet(showSheet: $showSheet)
		.additional.presentationDetents_before_iOS18_0(height: 400)
}

There might be easier ways to do some of this, but it works for me.

Thanks for the detailed feedback. I get it that it's not practical to target pre-release betas. With #available checks, i use that, i even have this package which has various backwards compatible modifiers for new APIs. It follows same concept as your Additional struct.

My question on how to handle crashes is not limited to just iOS version variations issues. I was refering to general exceptions and runtime errors that can cause app termination. Thanks.

My question on how to handle crashes is not limited to just iOS version variations issues. I was refering to general exceptions and runtime errors that can cause app termination. Thanks.

TEST! You need to test your app on different versions of the operating system, and fix any bugs you find.

Proactively code so that your app handles failures gracefully.

For example, don't always assume there's going to be a value and force unwrap things. Provide a default value and handle it, i.e. some.filter { $0.abc == "xyz" }.first! should be some.filter { $0.abc == "xyz" }.first ?? defaultThing.

Use guard let and if let.

.glassEffect(_in:) crushing on iOS 26 public beta.
 
 
Q