Post

Replies

Boosts

Views

Activity

Switching language sometimes makes the app freeze
I followed the advice from one of the latest WWDC videos on how to handle localization and in my app I launch Settings of my app when the user wants to change the app language (not system language). The user can then select one of the available languages that my app is localized for. The localization part works well, but sometimes it happens that when I click the < My app button in the leading, top corner or just navigate back to my app, I encounter a frozen screen and then the app just quits and restarts after 2-3 seconds. I don't need to preserve any state when the user changes the language, but I would certainly like to prevent this freeze from happening. The desired behaviour would be that the app restarts once the use changes the app language. I use SwiftUI as the UI framework. I use the following code to open the Settings of my app for the user: UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!) How can I achieve that?
1
0
1.5k
Sep ’21
AVSpeechSynthesizer - how to run callback onError
I use AVSpeechSynthesizer to pronounce some text in German. Sometimes it works just fine and sometimes it doesn't for some unknown to me reason (there is no error, because the speak() method doesn't throw and the only thing I am able to observe is the following message logged in the console): _BeginSpeaking: couldn't begin playback I tried to find some API in the AVSpeechSynthesizerDelegate to register a callback when error occurs, but I have found none. The closest match was this (but it appears to be only available for macOS, not iOS): https://developer.apple.com/documentation/appkit/nsspeechsynthesizerdelegate/1448407-speechsynthesizer?changes=_10 Below you can find how I initialize and use the speech synthesizer in my app: class Speaker: NSObject, AVSpeechSynthesizerDelegate {   class func sharedInstance() -> Speaker {     struct Singleton {       static var sharedInstance = Speaker()     }     return Singleton.sharedInstance   }       let audioSession = AVAudioSession.sharedInstance()   let synth = AVSpeechSynthesizer()       override init() {     super.init()     synth.delegate = self   }       func initializeAudioSession() {     do {       try audioSession.setCategory(.playback, mode: .spokenAudio, options: .duckOthers)       try audioSession.setActive(true, options: .notifyOthersOnDeactivation)     } catch {             }   }       func speak(text: String, language: String = "de-DE") { guard !self.synth.isSpeaking else { return }     let utterance = AVSpeechUtterance(string: text)     let voice = AVSpeechSynthesisVoice.speechVoices().filter { $0.language == language }.first!           utterance.voice = voice     self.synth.speak(utterance)   } } The audio session initialization is ran during app started just once. Afterwards, speech is synthesized by running the following code: Speaker.sharedInstance.speak(text: "Lederhosen") The problem is that I have no way of knowing if the speech synthesis succeeded—the UI is showing "speaking" state, but nothing is actually being spoken.
0
0
850
Aug ’21
Limit available app languages
I have my app localized for many languages, but I'd like to limit the available app languages to only a subset of those, because the content is not ready for all of them. I don't want to delete localization files, because they contain some useful translations that I will use in the future. The only thing I was able to find and try out is this piece of code: class AppDelegate: NSObject, UIApplicationDelegate {   func application(     _ application: UIApplication,     didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?   ) -> Bool {           UserDefaults.standard.set(["Base", "pl", "de", "ru"], forKey: "AppleLanguages")     UserDefaults.standard.synchronize()           ApplicationDelegate.shared.application(       application,       didFinishLaunchingWithOptions: launchOptions     )     return true   } } but unfortunately it does not work. When I launch Settings of my app, I can still choose from about 20-30 languages that I have already some translations for.
4
0
1.7k
Aug ’21
Do I need separate SKProduct for subscription with and without trial?
Hi, I am setting up auto-renewable subscriptions for my app. I have set up 4 subscriptions for 1,3,6, and 12 months with a one week free trial. Works like a charm, everything is displayed properly on device, etc. But now I need to take into account multiple cases and one of them is when the user has already consumed the free trial, cancelled the subscription, and then is about to subscribe again. I don't want to present "1 Week Free Trial" on the payment screen and certainly I don't want the user, who has already used the trial, to be eligible to use it again. So the question is if I need 2 sets of subscriptions in total? With Trial: my_app_1_month_trial my_app_3_months_trial my_app_6_months_trial my_app_12_months_trial And without trial: my_app_1_month my_app_3_months my_app_6_months my_app_12_months And then when user has already used the free trial (this piece of information will be either fetched from my server or an apple receipt), I add use the SKProducts from the "without trial" set and the user is charged immediately.
1
0
721
Aug ’21
SplitView navigation broken on iPad
I have two tabs in my app that contain a view with a list of items. When user taps an item, the navigation to detail view is triggered. On iPhone the list view takes the whole screen and it works just fine. However, on iPad those views are rendered in SplitView with the list of items on the left and the detail view on the right and the navigation works only for the first tap. After that, tapping any item doesn't change the detail view at all. I can see the following message in the console: Unable to present. Please file a bug. One of the views has an option to switch between SplitView and StackedView and the navigation works just fine in the StackedView on iPad. So clearly there is a problem with navigation in the SplitView. I just updated my iPad OS to 14.7 and still doesn't work, but it worked just fine on iPad OS 13 and 14... 40% of my app on iPad has become useless, because user simply cannot navigate to the simplest detail view :/ Has anyone else encountered this?
0
0
496
Jul ’21
Showing the correct price based on user's location
Hi, I am preparing to launch an app that will use subscription model. I am a solo developer and I have recently discovered the price tiers, which sound great to me, because I will be able to pick one price tier and have Apple adjust the price and currency for different regions. My problem is, once I pick a price tier, how do I know which price and currency to display in the app. It would be ideal if I could set up the pricing in App Store Connect and then use a built-in API to fetch the pricing in the app and it would magically already display the price and currency matching the user's region. Any hints?
0
0
510
Apr ’21
Sing in with Apple logo alignment
My app offers login via Apple and Facebook and I would like the logos of both buttons to be aligned. By default apple's logo is centrally aligned on the leading side of the text and facebook's logo is aligned to the leading edge. It makes it look as follows: [__________X_Continue with Apple___________] [_Y__________Continue with Facebook________] (where X is the apple logo, Y is the Facebook logo and _ is whitespace). The closest hint I found on how to do that is this: Inset the logo if necessary. If you need to horizontally align the Apple logo with other authentication logos, you can adjust the space between the logo and the button’s leading edge. (source: https://developer.apple.com/design/human-interface-guidelines/sign-in-with-apple/overview/buttons/#:~:text=If%20you%20need%20to%20horizontally,8%25%20of%20the%20button's%20width.) But how do I do that? I use SwiftUI and I wrap the login with Apple button with a UIViewRepresentable. The ASAuthorizationAppleIDButton class doesn't offer logo alignment property (only ButtonType and ButtonStyle). Any advice on how to do it would be appreciated.
0
1
956
Feb ’21
SwiftUI Text.strikethrough() not working
I have a piece of code that turns a string into a Text with attributes like italics, bold, etc. I apply attributes per character (or perhaps per stringIndex depending on the language) and then join everything using .reduce(Text(""), {t1, t2 in t1 + t2 }). The thing is that this had been working great (last time it worked was 7th September 2020), but now it turned out that is just stopped to work only for strikethrough(). It still works fine for bold(), italics() and underline(). I have iOS 14.1 installed on my iPhone and I build the project in xCode for iOS 14.0. Looks like something might have changed in the underlying API for the strikethrough method. The input string is in the following format: orange -> ein orang~er~ Wagen (^ein orang~eer~ Wagen^) where ~ - underline ^ - strikethrough It works as follows: I go through string indices to extract which indices have attributes, where the function returns the following type: [String.Index: Set<Character>] For instance for a string l~o^l^~ it should produce: [ &#9;1: [~], &#9;2: [~], &#9;3: [^, ~], &#9;4: [^], &#9;5: [~], &#9;6: [~] ] then I go through the string using its .indices, I discards the signs themselves and then apply attributes if the index is present in the aforementioned mapping of indices to attributes like this: func createAttributeText(str: String) -> Text { &#9;let attributeIndices: [String.Index: Set<Character>] = ... &#9;return str.indices.map { index in &#9;&#9;&#9; if let attributes = attributeIndices[index] { &#9;&#9;&#9;&#9;&#9;&#9;/* returns e.g. Text(str).strikethrough() &#9;&#9;&#9;&#9;&#9;&#9;&#9; or Text(str).bold().strikethrough() &#9;&#9;&#9;&#9;&#9;&#9;*/ &#9;&#9;&#9;&#9;&#9;&#9;return applyAttrs(text: str, attrs: attrs) &#9; else { &#9;&#9;&#9;&#9;&#9;&#9;return Text(str) &#9;&#9;&#9; } &#9;} &#9;.reduce(Text(""), {t1, t2 in t1 + t2 }) } and then VStack { &#9;&#9; createAttributedText(str: someStringVariable) } I can swear that this worked and I haven't touched the code. Is there any place where I can find a change log if there have been any changes to this part of the API? I tried to reproduce with a minimal example in another project, but so far it is working there so I need to keep digging.
2
0
2.7k
Nov ’20