Post

Replies

Boosts

Views

Activity

Reply to Fatal error calling TranslationSession.translate(String) in iOS 18
I get the same error in the same place: .onChange(of: vm.appleTraslationSourceText, { _, newValue in guard configuration == nil else { configuration?.invalidate() return } configuration = TranslationSession.Configuration( source: sourceLanguage, target: targetLanguage) }) .translationTask(configuration) { session in Task { @MainActor in do { let response = try await session.translate(vm.appleTraslationSourceText) // <- fatal error here targetText = response.targetText } catch { // code to handle error } } } This code, like yours, is very similar to Apple's demonstration code for translationTask(_:action:) In my app you tap words to get a translation. If I tap too quickly on different words the crash will occur generating this error: Translation/TranslationError+TranslationOnly.swift:54: Fatal error: Attempted to use TranslationSession after the view it was attached to has disappeared, which is not supported. Instead of storing a TranslationSession instance outside of the .translationTask closure, trigger a .translationTask to run again on a visible view and use that TranslationSession instance. and Refusing new translation request because text session has already been cancelled So my problem seems to occur when requesting a new translation before the previous one has been returned. Your scrollview could be requesting translations very often when scrolling?
Oct ’24