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:
[
	1: [~],
	2: [~],
	3: [^, ~],
	4: [^],
	5: [~],
	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 {
	let attributeIndices: [String.Index: Set<Character>] = ...
	return str.indices.map { index in
			 if let attributes = attributeIndices[index] {
						/* returns e.g. Text(str).strikethrough()
							 or Text(str).bold().strikethrough()
						*/
						return applyAttrs(text: str, attrs: attrs)
	 else {
						return Text(str)
			 }
	}
	.reduce(Text(""), {t1, t2 in t1 + t2 })
}
and then
VStack {
		 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.
Post
Replies
Boosts
Views
Activity
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.
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?
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?
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.
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.
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.
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?
I am slowly distributing my app to Beta testers via TestFlight. A few of them have already reported that the app showed “No Internet connection” while on WiFi. As soon as they switched to cellular everything started to work. But the WiFi worked for them for everything else.
One of the testers installed the app today for the first time. Still no Internet connection after switching back to WiFi from cellular.
I use Alamofire as a framework to make HTTPRequests and when these requests fail, “No Internet connection” error is displayed.
My backend service is hosted on Google Cloud, my domain is registered using AWS Route 53. I use SSL certificates managed by Google.
All HTTPRequests are sent to https://api.myapp.com (where myapp.com is hosted on AWS).
All of the testers have Automatic DNS resolution set in Settings -> WiFi -> (i) -> DNS
So far it occurred on iPhone XR and iPhone 12.
iOS versions 14.X
Any ideas how I can further investigate this issue?
Thanks
I am following "What's New in StoreKit" from WWDC17 to set up payment for subscriptions in my app and the author of the talk recommends to set applicationUsername to an opaque user ID.
When I tried to set it, it turned out it is readonly. (iOS 15)
Is this still a recommended practice, to set that property on SKPayment?
Thanks
I have been following these resources to set up auto-renewable subscriptions in my app written in SwiftUI:
What's new in StoreKit (WWDC17)
Advanced StoreKit (WWDC17)
https://blckbirds.com/post/how-to-use-in-app-purchases-in-swiftui-apps/
I basically have a class that implements SKProductsRequestDelegate instantiated in SubscribeView that processes the transactions. I was able to complete the entire flow in Sandbox (got the receipt and the server notification, created a corresponding subscription entry in my database).
The response coming from the verifyReceipt endpoint is quite complex and I am not sure if I understand it correctly. I am looking for an easy solution to get the latest subscription state. I don't want to focus on churn rate or anything else now.
Questions:
Does on-device receipt get automatically modified when the user cancels or modifies the subscriptions or when the trial period ends? If yes, can I rely on resubmitting the latest receipt from the device to my backend in order to keep track of the latest subscription state? I could resubmit the latest receipt on app startup, the server would verify and possibly update the subscription.
In the Advanced StoreKit (WWDC17) talk, it is mentioned to implement SKProductsRequestDelegate as soon as possible (e.g. in the AppDelegate). Do I even need that if I already have that delegate implemented in the SubscribeView? If I understood correctly, the purpose of that would be to be notified of the transactions done after some time (subscription change, cancellation, entering grace period, etc.). I'd prefer to ignore these for now and just rely on resubmitting the latest receipt to check the current subscription.
I need to add frames to auto-generated screenshots for multiple devices and multiple languages so that I can display these on my app's landing page. I guess it must be quite a standard task so my question is:
Is there anything that can be reused to get this job done?
All screenshot file names contain:
language
device name
generation
I would prefer not to have to manually add frames to 10 screenshots * number_of_devices * number_of_languages.
Right now I actually only need iPhone Pro (not Max) and iPad Pro 12.9 (newest gen), but in the future I might need it for other devices too.
I store the information whether the user has premium subscription in the KeyChain.
I just have a global function called doesUserHavePremium that reads a value from the KeyChain.
It appears that sometimes that value is read from the KeyChain incorrectly—even though I am 100% sure it is set, it returns nil. This happens only when the app was launched, then left for some time (probably screen got locked), and then I reentered the app again without relaunching it from scratch.
I tried the following things:
loosening the KeyChain access the the least restrictive
the following piece of code to notify UI elements whenfalse/trueis read for that value after previously not being able to access it
let protectedDataAvailabilityNotificationName = UIApplication.protectedDataDidBecomeAvailableNotification
func observeProtectedDataAvailability() {
let selector = #selector(Self.protectedDataAvailableNotification)
switch UIApplication.shared.isProtectedDataAvailable {
case true: break
case false:
NotificationCenter.default.addObserver(self,
selector: selector,
name: protectedDataAvailabilityNotificationName,
object: nil)
}
}
@objc func protectedDataAvailableNotification(notification: NSNotification) {
NotificationCenter.default.removeObserver(self, name: protectedDataAvailabilityNotificationName, object: nil)
dataDidBecomeAvailable()
}
func dataDidBecomeAvailable() {
refreshSubscriptionStatusSubscribers()
}
But it doesn't seem to work. The problem is that I cannot debug it, because the app has to enter background in order for this problem to manifest itself.
I have read several threads related to this issue here and on GitHub and it seems like there isn't any great solution. I am looking for some workarounds. Any hints are welcome. I will try the following now:
Try to store that value in UserDefaults instead—it is not really a secret like a password/token, but I need to be sure it cannot be tampered with. Not sure if UserDefaults suffer from the same problem.
Try to refactor to code to wrap the doesUserHavePremium and cache its return value in a property. That seems promising, because it never happens during fresh start thus I could always set that property on the app startup.
After running automated UI tests it turned out that my app looks quite different on iPad simulator than on real iPad.
I have my iPad Pro 12,9" right next to me and the app looks completely fine, but on Simulator (same device model on Simulator) the geometry is simply wrong.
I use SwiftUI's GeometryReader to properly place elements, add horizontal padding if the screen width is wide and in landscape orientation.
It is not the worst case, because on real device everything looks fine, but I wanted to use screenshots generated by these tests and the ones taken on iPad Simulators are simply useless. iPhone Simulator is totally fine.
Am I doing something wrong? Has anybody encountered this?
I run the tests in the following way:
projectName="./MyProject.xcodeproj"
schemeName="MyProject"
simulators=(
...
"iPhone 12 Pro Max"
...
"iPad Pro (12.9-inch) (5th generation)"
...
)
languages=(
"en"
...
)
appearances=(
"light"
"dark"
)
xcrun simctl boot "$simulator"
xcrun simctl ui "$simulator" appearance $appearance
xcodebuild -testLanguage $language -scheme $schemeName -project $projectName -derivedDataPath '/tmp/MyProjectDerivedData/' -destination "platform=iOS
Let's say I want to create an introductory offer starting from the 1st of November till the end of the year. (it should begin at 01-11-2021 00:00:00 and expire at 31-12-2021 23:59:59)
Which of the options below is correct in that case?
Option 1
Start date: 1 November
End Date: 31 December
Option 2
Start date: 1 November
End Date: 1st of January