Post

Replies

Boosts

Views

Activity

Reply to If I can custom master detail view's width in SwiftUI
I was looking for the same option. I tried setting a fixed width by using a geometry reader. GeometryReader { geo in NavigationView { List() .frame(minWidth: geo.size.width/3) } } This does actually change the width, but the origin of the view moves out to the left. You can change the position, but then the view will be cropped on the right. The actual width of the main navigation view does not change
Jun ’20
Reply to .onChange with ScenePhase not working
This issue persists on watchOS 8 Beta. It's not just that the onChange is not called. It is also not updating the variable at all (in some cases). As this seems to be unreliable I went for this solution, which is not recommended, but 100% reliable: 1. Create an ExtensionDelegate / AppDelegate It just serves to send notifications when the state of the app changes. For watchOS this would be: class ExtensionDelegate: NSObject, WKExtensionDelegate {     func applicationDidBecomeActive() {         NotificationCenter.default.post(name: Notification.Name.App.scenePhaseChanged, object: nil, userInfo: ["scenePhase": ScenePhase.active])     }     func applicationWillResignActive() {         NotificationCenter.default.post(name: Notification.Name.App.scenePhaseChanged, object: nil, userInfo: ["scenePhase": ScenePhase.inactive])     }          func applicationDidEnterBackground() {         NotificationCenter.default.post(name: Notification.Name.App.scenePhaseChanged, object: nil, userInfo: ["scenePhase": ScenePhase.background])     } } 2. Create a custom ScenePhase environment key This serves as a replacement for the actual key, which is not updated reliably. extension EnvironmentValues {     var customScenePhase: ScenePhase {         get {self[CustomScenePhaseKey.self]}         set {self[CustomScenePhaseKey.self] = newValue}     } } private struct CustomScenePhaseKey: EnvironmentKey {     static let defaultValue = ScenePhase.inactive } 3. Process updating notifications with the new scenePhase var appStateChangeNotification = NotificationCenter.default.publisher(for: Notification.Name.App.scenePhaseChanged) //.... .onReceive(self.appStateChangeNotification, perform: { notification in                     let newScenePhase: ScenePhase = notification.userInfo?["scenePhase"] as? ScenePhase ?? .active                     guard newScenePhase != self.scenePhase else {return}                     self.scenePhase = newScenePhase                 }) 4. Forward the new scenePhase ContentView() .environment(\.customScenePhase, self.scenePhase) I hope this sample code helps anyone with similar issues
Jun ’21
Reply to How to add swift availability check to Environment values?
The answer I found to this is not really satisfying, but it works fine with SwiftUI. Every time the variable isLuminanceReduced changes, the ExtensionDelegate also changes the app state and calls applicationWillResignActive(). So to keep backwards compatible I introduced a singleton class that just holds a Bool isOn: class LuminanceReducedCompat: ObservableObject {     @Published var isOn: Bool = false     public static let shared = LuminanceReducedCompat()     private var notifcationObservers = [Any]()     private init() {} } Now you can change the isOn variable in the applicationWillResignActive(). On your SwiftUI views you can add a that object now as an observed object. @ObservedObject var luminanceReducedCompat = LuminanceReducedCompat.shared I know that's not really nice, but the best I found until now. I don't want to maintain 2 views that show the same. I though about using a custom Environment Value that reflects the official watchOS 8 value, but I am not sure how to push this into the view stack correctly and update it.
Sep ’21
Reply to Does Always-on screen require watchOS 8 as a minimum deployment target?
I did a bunch of testing, like setting the target back to watchOS 7 and 6 and it still worked. Then I deleted and completely reinstalled the app with watchOS 6 as a deployment target and it kept working. So I guess that the main issue here might be an issue during an update. So that after an update the watch does not recognize that the app is always-on capable, but after reinstallation it does so. Hopefully the same issue does not occur with App Store updates
Sep ’21
Reply to .sheet no longer dismissable in WatchOS 7?
Seems to continue in watchOS 8. I have filed feedback about this with the release of watchOS 7 already. (FB9055341) EDIT: On Stackoverflow I found out that this issue is actually due to a SwiftUI change. The title of a sheet on watchOS is no longer an actual title, but a button in a toolbar. To change it you can overwrite the toolbar: MySheet().toolbar {                 ToolbarItem(placement: .cancellationAction) {                     Button(title, action: action)                 }             } In the action you can use the environment value for presentationMode to close the sheet. The button will be clickable and it will replace the cancel title. So this is more a documentation and restructuring issue that almost no one caught. Source: https://stackoverflow.com/a/64194674/1203713
Oct ’21
Reply to Implemented AppIntent doesn't show in Shortcuts app
I had the same issue. I could fix it by setting the Xcode-select to the Xcode-beta version. Now for me all the AppIntents appear in the shortcuts app. When you want to create an AppShortcut, you should omit custom AppEntity based parameters from the phrases. Otherwise, they don't appear in the shortcuts app and are not usable by Siri. This is likely a bug and I already filed feedback for it.
Jun ’22
Reply to MusicKit - Search Apple Music Catalog without user authorization
I discovered that it's possible the developer token directly with try await MusicDataRequest.tokenProvider.developerToken(options: []). Unfortunately, this returns another error: Encountered error while requesting developer token. Error Domain=ICError Code=-7010 "Failed to get listener endpoint for cloud service status monitor." UserInfo={NSDebugDescription=Failed to get listener endpoint for cloud service status monitor....
Dec ’22
Reply to Apple Watch cannot reconnect
I managed the solve this issue by Unpair watch and iPhone from Xcode (right-click). Quit Xcode and disconnect the iPhone (Airplane mode) Remove trusted computers on both devices. Disable developer mode Restart both devices. Connect the iPhone and trust the computer using Finder Open Xcode and pair the iPhone (trust again) Enable developer mode on watch and iPhone It should work. This was basically following the advice in this post + unpairing the devices from Xcode: https://forums.developer.apple.com/forums/thread/734694?page=2
Apr ’24