Post

Replies

Boosts

Views

Activity

watchOS Simulator Version 14.0.1 (986.3) not syncing HealthKit from iPhone to paired Apple Watch
I have a project that's been on the App Store for more than a year. I used to do ASC screenshots and debugging on Simulator with a few Watch Simulators (screen sizes) paired to one iPhone simulator sharing the same HealthKit example data and settings like units and regions / languages. Since updating to Xcode 14 I can't get the HealthKit related data and settings to sync between and iPhone Simulator and it's paired watch Simulators. Any idea what I am doing wrong now? I should note that my project is still using iOS App, WatchKit App and WatchKit Extension. I haven't yet switched to single-target WatchApp.
1
0
954
Oct ’22
Neither getCurrentTimelineEntry nor getLocalizableSampleTemplate get called by Complication Controller
I have an iPhone with Watch Project, I was getting good results on my Complications but lately they don't want to update… When I build and run on my iPhone the new Watch build gets transferred to the paired watch and is running there fine. Almost: it refuses to update the Complications. After Watch restart I only get ----- My server correctly tells me that I have two active complications on the current watchFace and I am calling server.reloadTimeline(for:) on both of them but the getCurrentTimelineEntry function never gets executed by the server. Neither does the getLocalizableSampleTemplate When I remove the App from the Watch, restart the Watch and then put the App back on the Watch using the iPhone's Watch App -- then it works, but only about 3 minutes after starting the Watch App on the Watch. During these 3 minutes my app's complications are only --. I can't ship it like this… My hunch is that somewhere the complication controller crashes, but it doesn't take my app down with it and thus my complications don't work any more. All other apps' complications do update alright though. Now my question is: is that a bug in Xcode, in WatchOS, or in my code? Will this happen when I first deploy my app on the App Store or will it be an issue with updates via App Store? Is this only relevant for my "local" build? Any hints where to hunt this bug?
1
0
1.6k
Aug ’21
HKQuery.predicateForSamples - how is endDate: nil interpreted
I'm trying to get all samples after a given startDate and have that query running for as long as the app is "alive" including background. I used let predicate = HKQuery.predicateForSamples(withStart: queryStart, end: nil, options: HKQueryOptions.strictStartDate) I thought: if its not specified it cannot be restricting… From the results I am getting I infer that it's using the end of the day the query is executed as a restriction: I am getting all updates the same day with the samplesUpdatequeryResultshandler but the next morning my app doesn't receive samples unless I restart it. Edit: I should mention I am using options: HKQueryOptions.strictStartDate Is it too much to ask that the documentation mention how nil is handled if it's allowed? One could omit the ? and everyone would know to specify the end date. I'll now use let queryEndDate = Calendar.current.date(byAdding: .year, value: 10, to: Date())! See how that goes.
0
0
896
Aug ’21
SF Symbol using string interpolation
I was very happy when I saw this: "You can embed a symbol inside a run of text by using string interpolation." Text("Thalia… \(Image(systemName: "chevron.forward"))") Unfortunately this is a feature of SwiftUI and not generally available string interpolation. In places where a string is expected like an Apple Watch Compilcation Text Provider CLKSimpleTextProvider(text: "\(Image(systemName: "heart"))") this doesn't return an inline Image but "Image(provider: SwiftUI.ImageProviderBox<SwiftUI.Image.(unknown context at $18487da20).NamedImageProvider>)" So… Is there a way to include an SF Symbol in a regular string to wiggle it into a CLKSimpleTextProvider?
2
0
2.7k
Jun ’21
Xcode 13 Beta if I only have one single Mac
I only have one Mac and I would like to be able to reliably update my apps before iOS 15 and Xcode 13 become publicly available explore features of iOS15 and Xcode 13 Betas. Can I install Xcode 13 Beta parallel to my current stable Xcode 12? How do I make sure both versions don't interfere with each other? Of can I / should I trust stability of Xcode 13 Beta and just jump right in? Will apps targeted for iOS14 be accepted on the App Store if built by Xcode 13 Beta?
3
0
5k
Jun ’21
How do I modify a SwiftUI Gauge so that it fills the parent View completely?
Hello, I want to use the Gauge View with circular style not only in my app's complications but also in the watchOS app. When I put the Gauge in my View it just sits right in the middle and I cannot figure out how to scale it up. .resizable() is not available. .scaledToFill() and .scaledToFit()don't do anything .scaleEffect(3) makes the Labels blurry Gauge(value: 0.5, in: 0...1,       label: { Text("Gauge") },       currentValueLabel: { Text("0.5") },       minimumValueLabel: { Text("0") },       maximumValueLabel: { Text("1") } ).gaugeStyle(CircularGaugeStyle()) What am I missing?
0
0
1.3k
Mar ’21
How to combine updating of Text(date, style: .relative) with styling of formatter:
Consider the code below... The green box using style: .relative is updating the relative time continuously, but it has too much detail for my taste. The red box using formatter: rFormatter has exactly the right detail but it doesn't update unless I force it to - maybe a timer or something? How do I most efficiently combine the formatting I want with the continuous updating? struct ContentView: View {     var relDate: Date {         let comps = Calendar.current.dateComponents([.hour, .day, .month, .year], from: Date())         return Calendar.current.date(from: comps)!     }     let rFormatter = RelativeDateTimeFormatter()     init() {         rFormatter.dateTimeStyle = .named     }     var body: some View {         VStack {             Text(relDate, style: .relative)                 .padding()                 .background(Color(.green))             Text(relDate, formatter: rFormatter)                 .padding()                 .background(Color(.red))         }     } }
3
0
1.3k
Mar ’21
MeasurementFormatter workaround for missing .unitStyle = .none?
I was trying to write a function that returns a localized string for a weight measurement - but with the option of skipping the unit substring. As in: return "100,1" instead of "100,1kg" but respecting the user's locale. First thought was: just specify unitStyle = .none but that is not a valid member. So I came up with this solution which works for pounds and kilos but there sure are other weight / mass units out there... How do I retrieve the user's preferred unit from locale? func formatWeight(weightInKgs value: Double, skipUnit: Bool = false) - String {     let weightInKgs = Measurement(value: value, unit: UnitMass.kilograms)     if !skipUnit {         let formatter = MeasurementFormatter() //        if skipUnit { //            formatter.unitStyle = .none //        } else {             formatter.unitStyle = .short //        }         formatter.numberFormatter.maximumFractionDigits = 1         formatter.numberFormatter.minimumFractionDigits = 1         return formatter.string(from: weightInKgs)     } else {         if Locale.current.usesMetricSystem {             let formatter = NumberFormatter()             formatter.maximumFractionDigits = 1             formatter.minimumFractionDigits = 1             return formatter.string(from: NSNumber(value: weightInKgs.value))!         } else {             let weightInLocaleUnit = weightInKgs.converted(to: UnitMass.pounds) //this is not universal             let formatter = NumberFormatter()             formatter.maximumFractionDigits = 1             formatter.minimumFractionDigits = 1             return formatter.string(from: NSNumber(value: weightInLocaleUnit.value))!         }     } }
2
0
1.4k
Mar ’21
SwiftUI Runtime Error from if condition { Text() } in watchOS
As far as I read about conditional Views this code should work. But it doesn't. struct Consts { static let myCondition = false /* no difference if true or false */ } struct ContentView: View { @State var toggle: Bool = false var body: some View { List() { Text("Short Text is in first line") Text("Second Line Text is a little longer but not much") if Consts.myCondition { Text("This is a conditional text. As in: when the user hasn't purchased the option he / she don't need a hint how to use this feature.") /* } else { Text("else doesn't help either.") */ } Toggle("I also have a toggle but it has nothing to do with this.", isOn: $toggle) Text("Here we have a longer Text. Dont know what to type any more.") Text("More text which is longer than a few lines.") Text("Not so long Text") } .navigationTitle("Hints &amp; Settings") } } It compiles without warnings or errors. It loads up and displays fine, on simulator and on device. But every time I scroll the List upwards from the end, as soon as this if condition { Text() } should become visible the app crashes with Fatal error: file SwiftUI, line 0 2021-03-07 06:36:26.548126+0100 WTFif WatchKit Extension[23163:641812] Fatal error: file SwiftUI, line 0 This is not limited to watchOS. It reproduces the same way in iOS, just the Texts have to be longer so that the if condition { Text() } becomes invisible when scrolling. I have worked around the error with an array, conditional ranges and two ForEach() blocks. struct ContentView: View { let myHints = ["Short Text is in first line", "Second Line Text is a little longer but not much", "This is a conditional text. As in: when the user hasn't purchased the option he / she don't need to hint how to use this feature.", "Here we have a longer Text. Dont know what to type any more.", "More text which is longer than a few lines.", "Not so long Text"] var myUpperRange: ClosedRangeInt { if Consts.myCondition { return 0...1 } else { return 0...2 } } var myLowerRange: ClosedRangeInt { return 3...5 } @State var toggle: Bool = false var body: some View { List() { ForEach (myUpperRange, id: \.self) { i in Text(myHints[i]) } Toggle("I also have a toggle but it has nothing to do with this.", isOn: $toggle) ForEach (myLowerRange, id: \.self) { i in Text(myHints[i]) } } .navigationTitle("Hints &amp; Settings") } } My question basically is: am I not getting it or did I find a bug in Xcode / SwiftUI? Should my code above work? What could I have done different to make it work with the simple list of Texts? Background: I also have a TabView with an if condition { MyTab() } which works without crashing. Do I have to worry that this might crash in the same way? Should I work around this as well before shipping? PS: I am using Xcode 12.4 (12D4e)
4
0
2.0k
Mar ’21
What’s the correct way to implement getTimelineEndDate(for:withHandler:)?
Maybe I’m getting this all wrong. The video says… handler(timeline(for: complication)?.endDate) (but it doesn’t indicate how / if this .endDate is set. Why would one write to a timeline.endDate inside the func if it is set by this func? What is the timeline var anyway? the docs - https://developer.apple.com/documentation/clockkit/creating_and_updating_complications say handler(Date().addingTimeInterval(24.0 * 60.0 * 60.0)) but there is no switch for complication. Now I’m thinking: switching by complication one can chose which endDate to handle. Is that correct?
2
0
1k
Feb ’21
How to add Images to Swift Playground for iPad?
I am trying to do this tutorial on my iPad (don’t have a Mac running Xcode): https://developer.apple.com/tutorials/swiftui/creating-and-combining-views#Create-a-Custom-Image-View I’m getting stuck at the point where I want to add an image. I did manage to import an image to my resources (the box behind the plus sign at the top right of the screen). Now when I reference the image’s name in code I don’t get an error but I also don’t get to see the image. When I try to tap-image-to-include-in-the-code I get a little emoji like thing that looks like an image but how is that supposed to work? If I just put it on a line of code I throws the error “build block requires URL to conform to View”     var body: some View {         VStack(alignment: .center) {             Text("image following") fileLiteral(resourceName: "Foto.png")             Image("IMG_1249.png")             .clipShape(Circle())             .overlay(                 Circle().stroke(Color.black, lineWidth: 4))             .shadow(radius: 10)              }     } }
2
0
3.9k
Nov ’20