Post

Replies

Boosts

Views

Activity

Picker with SF Symbols like in WWDC 2023 video
I'm trying to duplicate the Picker example at 31:39 in the "What's new in SwiftUI" WWDC 2023 video at https://developer.apple.com/wwdc23/10148. My code is at https://github.com/mvolkmann/PickerStyleDemo/blob/main/PickerStyleDemo/ContentView.swift. The attached screenshot shows what I get. Note that I don't see "tag" SF Symbol for each option like the WWDC video shows. Am I doing something wrong?
1
0
1.3k
Jun ’23
inspector view modifier
I'm trying to learn how to use the inspector view modifier. I have a very simple app here: https://github.com/mvolkmann/InspectorDemo/blob/main/InspectorDemo/ContentView.swift. Clicking the info button in the toolbar of the main view displays an inspector sheet. The inspector sheet has its own toolbar that displays buttons in a ControlGroup. Clicking the info button again dismisses the inspector sheet. The issue is that when I display the inspector sheet again, its toolbar is gone. Why does it only render the first time the inspector sheet is displayed?
0
0
425
Jun ’23
cycling workouts
I wrote an app that successfully adds a cycling workout to HealthKit. I can see in the Health app that there are new entries under "Workouts", "Active Energy", and "Exercise Minutes" all from me just adding an HKWorkout and a HKQuantitySample. However, there is no new entry for "Cycling Distance". I assumed that since the workout I added includes the fact that the activityType is HKWorkoutActivityType.cycling and I provided the distance, that it would also add an entry for "Cycling Distance". Is there something extra I need to do to get that?
2
0
955
Feb ’23
HealthKit HKWorkout totalEnergyBurned
I have an app that adds cycling workouts to HealthKit. Here is the snippet of code that does it. let workout = HKWorkout( activityType: HKWorkoutActivityType.cycling, start: startTime, end: endTime, duration: 0, // compute from start and end data totalEnergyBurned: HKQuantity( unit: .largeCalorie(), doubleValue: Double(calories) ), totalDistance: HKQuantity(unit: .mile(), doubleValue: distance), metadata: nil ) try await store.save(workout) This successfully adds a workout and the number of calories is recorded in the Health app. However, the iOS Fitness app and the watchOS Activity app do not recognize the calories so the MOVE ring is not affected. What else do I need to do to let those apps know that my workout burned calories?
2
0
812
Feb ’23
CaptureSample app fails to save files
I downloaded and built this app for capturing images that can be used to generate a USDZ 3D model file. But it doesn't work for me. I can take the photos and see them in the app, but there are not saved. Here are some of the log messages produced by the app. Note the last line. Creating capture path: "file:///var/mobile/Containers/Data/Application/40A7C69A-DE34-43B8-A1DF-D3BB87D5C23E/Documents/Captures/Jan%2029,%202023%20at%201:33:54%20PM/" Got back dual camera! didSet setupResult=success Starting session... Capture photo called... Found available previewPhotoFormat: Optional(["PixelFormatType": 875704422, "Width": 512, "Height": 512]) inProgressCaptures=1 Captured gravity vector: Optional(__C.CMAcceleration(x: 0.033207084983587265, y: -0.7901527881622314, z: -0.6120097041130066)) DidFinishProcessingPhoto: photo=<AVCapturePhoto: 0x280e04290 pts:388734.243725 1/1 settings:uid:4 photo:{4032x3024 SIS:ON} prev:{512x384} thumb:{512x384} time:0.741-0.797> [CIImage initWithCVImageBuffer:options:] failed because the buffer is nil.
0
0
843
Jan ’23
StoreKit 2 in-app purchase restore
Apps that support in-app purchases are rejected in App Review unless they implement the ability to restore previous purchases. There is a WWDC 2022 video on doing exactly that and I am doing what that video suggests, but my app is still rejected. Here's what they say: "When validating receipts on your server, your server needs to be able to handle a production-signed app getting its receipts from Apple’s test environment. The recommended approach is for your production server to always validate receipts against the production App Store first. If validation fails with the error code "Sandbox receipt used in production," you should validate against the test environment instead." To which I replied: "I don’t have a server. Can you explain what “your server” means for an iOS app that has no server-side components?" But they won't explain themselves. They just say: "Your question requires technical assistance and would be best addressed by Apple Developer Technical Support who can provide discrete code-level assistance for Apple frameworks, APIs, and tools." Can someone point me to a code example that shows how to do this? My failed attempt is here: https://github.com/mvolkmann/SwiftUI-GiftTrack/blob/main/GiftTrack/ViewModels/StoreViewModel.swift
2
0
3.3k
Sep ’22
update TabView background color
I can use this code to change the background color of the tab bar: let appearance = UITabBarAppearance() appearance.backgroundColor = UIColor(bgColor) let appearance2 = UITabBar.appearance() appearance2.scrollEdgeAppearance = appearance appearance2.standardAppearance = appearance But it seems this is a one-time thing. If I run this code again later with a different value of bgColor, it does not change. What can I do to modify the tab bar background color after I have set the color once? I need this because I am allowing the user to change it.
3
0
3.4k
Jul ’22
how to assign to Binding<String>
I have a custom view that is passed a Binding to a String. The custom view renders a TextField. I can't find the right syntax to modify the binding after focus leaves the TextField. The code is something like this: struct MyURL: View {     private let title: String     @Binding var url: String     @State private var tempUrl: String     init(_ title: String, url: Binding<String>) {         self.title = title         _url = url         _tempUrl = State(initialValue: url.wrappedValue)     }     var body: some View {     TextField(title, text: $tempUrl, onEditingChanged: editingChanged) .autocapitalization(.none)             .disableAutocorrection(true)         }     }     private func editingChanged(hasFocus: Bool) {         guard !hasFocus else { return }         if !tempUrl.starts(with: "https://"), !tempUrl.starts(with: "http://") {             tempUrl = "https://" + tempUrl         }         url.wrappedValue = tempUrl // THIS LINE IS WRONG!     } }
1
0
1.1k
Jul ’22
subviews vs. functions
I have a view that is getting large and I want to factor out a chunk of it. One option is to extract a subview by creating a new struct that inherits from View and defines the body property. Another option is to create a function with a return type of some View. It's a bit less code that way. But I get the impression that creating a new View is preferred. What advantages does that have? struct DemoView: View {  var body: some View {   Text("Demo")  } } vs. func demoView() -> some View {  Text("Demo") }
1
0
1.4k
May ’22
WatchConnectivity framework - Companion app is not installed
I created a pair of fairly simple apps (iOS and watchOS) that send messages to each other. It uses the WatchConnectiivity framework. When I run the two apps in the Simulator, I can send messages from the phone to the watch, but I cannot send messages from the watch to the phone. When I attempt that I get the message "Companion app is not installed". I've seen suggestions that I need to uncheck the "Supports Running Without iOS App Installation" checkbox, but when I do that, the iOS app no longer runs in the Simulator. My code is here: https://github.com/mvolkmann/watch-with-ios. I'd love to get some hints about how to work past this.
4
0
955
May ’22
getting started with Siri shortcuts/intents
I've spent about six hours so far trying to write a basic example of supporting Siri intents in a SwiftUI app to no avail. It seems most information on this topic online is out of date. I just want do something simple like activate a button in my app with a voice command. Can someone confirm that this is possible? So far this looks like the best description of the steps to set it up. https://medium.com/simform-engineering/how-to-integrate-siri-shortcuts-and-design-custom-intents-tutorial-e53285b550cf. But I think some steps are missing and it feels very complex.
0
0
692
May ’22