Post

Replies

Boosts

Views

Activity

Different toolbar item placement for iPhone vs iPad
On iPhone, I would like to have a more button at the top right of the navigation bar, a search field in the bottom toolbar, and a plus button to the right of the search field. I've achieved this via the code below. But on iPad they should be in the navigation bar at the trailing edge from left to right: plus, more, search field. Just like the Shortcuts app, if there's not enough horizontal space, the search field should collapse into a button, and with even smaller space the search bar should become full-width under the navigation bar. Right now on iPad the search bar is full width under the navigation bar, more at top right, plus at bottom middle, no matter how big the window is. How can I achieve that? Any way to specify them for the system to more automatically do the right thing, or would I need to check specifically for iPhone vs iPad UIDevice to change the code? struct ContentView: View { @State private var searchText = "" var body: some View { NavigationStack { VStack { Text("Hello, world!") } .navigationTitle("Test App") .searchable(text: $searchText) .toolbar { ToolbarItem { Menu { //... } label: { Label("More", systemImage: "ellipsis") } } DefaultToolbarItem(kind: .search, placement: .bottomBar) ToolbarSpacer(.fixed, placement: .bottomBar) ToolbarItem(placement: .bottomBar) { Button { print("Add tapped") } label: { Label("Add", systemImage: "plus") } } } } } }
2
0
51
6d
How to hide scroll edge effect until scroll down
I present a view in a sheet that consists of a navigation stack and a scroll view which has a photo pushed to the top by setting .ignoresSafeArea(edges: .top). The problem is the top of the photo is blurry due to the scroll edge effect. I would like to hide the scroll edge effect so the photo is fully visible when scrolled to the top but let the effect become visible upon scrolling down. Is that possible? struct ContentView: View { @State private var showingSheet = false var body: some View { VStack { Button("Present Sheet") { showingSheet = true } } .sheet(isPresented: $showingSheet) { SheetView() } } } struct SheetView: View { @Environment(\.dismiss) private var dismiss var body: some View { NavigationStack { ScrollView { VStack { Image("Photo") .resizable() .scaledToFill() } } .ignoresSafeArea(edges: .top) .toolbar { ToolbarItem(placement: .cancellationAction) { Button(role: .close) { dismiss() } } ToolbarItem { EditButton() } } } } }
1
0
60
6d
How to update action extension icon for iOS 26
iOS 26 seems to have changed the way action extension icons appear in the share sheet. My icon is too small now compared to the Copy button in Safari (and Shortcuts’ icons are too small too, a bug?). How do you update it, and how do you ensure it looks fine in iOS 18 and earlier? My current icon is an AppIcon in the asset catalog, single size 1024x1024, with about 130px padding around it.
0
0
60
6d
How to show confirmationDialog from a Button in a Menu
I have a More button in my nav bar that contains a Delete action, and when you tap that I want to show a confirmation dialog before performing the deletion. In order words, I have a toolbar containing a toolbar item containing a menu containing a button that when tapped needs to show a confirmation dialog. In iOS 26, you're supposed to add the confirmationDialog on the view that presents the action sheet so that it can point to the source view or morph out of it if it's liquid glass. But when I do that, the confirmation dialog does not appear. Is that a bug or am I doing something wrong? struct ContentView: View { @State private var showingDeleteConfirmation = false var body: some View { NavigationStack { Text("👋, 🌎!") .toolbar { ToolbarItem { Menu { Button(role: .destructive) { showingDeleteConfirmation.toggle() } label: { Label("Delete", systemImage: "trash") } .confirmationDialog("Are you sure?", isPresented: $showingDeleteConfirmation) { Button(role: .destructive) { print("Delete it") } label: { Text("Delete") } Button(role: .cancel, action: {}) } } label: { Label("More", systemImage: "ellipsis") } } } } } }
1
0
82
1w
AppIntent perform function is not invoked from ControlWidget
I have an AppIntent that edits an object in my app. The intent accepts an app entity as a parameter, so if you run the intent it will ask which one do you want to edit, then you select one from the list and it shows a dialog that it was edited successfully. I use this same intent in my Home Screen widget initializing it with an objectEntity. The code needs to run in the app's process, not the widget extension process, so the file is added to both targets and it conforms to ForegroundContinuableIntent, and that is supposed to ensure it always runs in the app process. This works great when run from the Shortcuts app and when involved via a button in the Home Screen widget, exactly as expected. Here is that app intent: @available(iOS 17.0, *) struct EditObjectIntent: AppIntent { static let title: LocalizedStringResource = "Edit Object" @Parameter(title: "Object", requestValueDialog: "Which object do you want to edit?", inputConnectionBehavior: .connectToPreviousIntentResult) var objectEntity: ObjectEntity init() { print("INIT") } init(objectEntity: ObjectEntity) { self.objectEntity = objectEntity } @MainActor func perform() async throws -> some IntentResult & ReturnsValue<ObjectEntity> & ProvidesDialog { // Edit the object from objectEntity.id... return .result(value: objectEntity, dialog: "Done") } } @available(iOS 17.0, *) @available(iOSApplicationExtension, unavailable) extension EditObjectIntent: ForegroundContinuableIntent { } I now want to create a ControlButton that uses this intent: struct EditObjectControlWidget: ControlWidget { var body: some ControlWidgetConfiguration { StaticControlConfiguration(kind: "EditObjectControlWidget") { ControlWidgetButton(action: EditObjectIntent()) { Label("Edit Object", systemImage: "pencil") } } } } When I add the button to Control Center and tap it (on iOS 18), init is called 3x in the app process and 2x in the widget process, yet the perform function is not invoked in either process. No error appears in console logs for the app's process, but this appears for the widget process: LaunchServices: store <private> or url <private> was nil: Error Domain=NSOSStatusErrorDomain Code=-54 "process may not map database" UserInfo={NSDebugDescription=process may not map database, _LSLine=72, _LSFunction=_LSServer_GetServerStoreForConnectionWithCompletionHandler} Attempt to map database failed: permission was denied. This attempt will not be retried. Failed to initialize client context with error Error Domain=NSOSStatusErrorDomain Code=-54 "process may not map database" UserInfo={NSDebugDescription=process may not map database, _LSLine=72, _LSFunction=_LSServer_GetServerStoreForConnectionWithCompletionHandler} What am I doing wrong here? Thanks!
1
0
68
3w
How to donate IndexedEntity, if required in iOS 26
In the Get to Know App Intents WWDC session, it was said New this year, you can now add Spotlight indexing keys directly on properties. Annotating properties allows Spotlight to show more relevant information to customers. When donating indexed entities, the framework will handle creating the searchable item and attribute set for you. After donating entities, they can be found in Spotlight. How do you donate indexed app entities? Making app entities available in Spotlight seems to state it's not necessary to donate entities: The system can automatically extract the keys for Spotlight indexing at compile time and store them in the App Intents metadata that Xcode generates as part of your app’s bundle. As a result, Spotlight indexing is faster and can find your app entities without launching your app, and without you having to explicitly donate the entities to Spotlight. You also don’t need to manually update or remove entities from the Spotlight index when your app’s data changes. Say I have a CarEntity. The user can create/update/delete cars at any time. What is the modern way to get cars to appear in Spotlight in iOS 26?
2
0
85
3w
How to initialize OpenIntent parameter when returning OpensIntent in perform
I have an app that lets you create cars. I have a CarEntity, an OpenCarIntent, and a CreateCarIntent. I want to support the Open When Run option when creating a car. I understand to do this, you just update the return type of your perform function to include & OpensIntent, then change your return value to include opensIntent: OpenCarIntent(target: carEntity). When I do this, I get a compile-time error: Cannot convert value of type 'CarEntity' to expected argument type 'IntentParameter<CarEntity>' What am I doing wrong here? struct CreateCarIntent: ForegroundContinuableIntent { static let title: LocalizedStringResource = "Create Car" @Parameter(title: "Name") var name: String @MainActor func perform() async throws -> some IntentResult & ReturnsValue<CarEntity> & OpensIntent { let managedObjectContext = PersistenceController.shared.container.viewContext let car = Car(context: managedObjectContext) car.name = name try await managedObjectContext.perform { try managedObjectContext.save() } let carEntity = CarEntity(car: car) return .result( value: carEntity, opensIntent: OpenCarIntent(target: carEntity) // FIXME: Won't compile ) } } struct OpenCarIntent: OpenIntent { static let title: LocalizedStringResource = "Open Car" @Parameter(title: "Car") var target: CarEntity @MainActor func perform() async throws -> some IntentResult { await UIApplication.shared.open(URL(string: "carapp://cars/view?id=\(target.id)")!) return .result() } }
2
0
87
Jun ’25
How to replace layoutManager with textLayoutManager for a flexible dynamic height UITextView
In order to create a UITextView like that of the Messages app whose height grows to fits its contents (number of lines), I subclassed UITextView and customized the intrinsicContentSize like so: override var intrinsicContentSize: CGSize { var size = super.intrinsicContentSize if size.height == UIView.noIntrinsicMetric { layoutManager.glyphRange(for: textContainer) size.height = layoutManager.usedRect(for: textContainer).height + textContainerInset.top + textContainerInset.bottom } return size } As noted at WWDC, accessing layoutManager will force TextKit 1, we should instead use textLayoutManager. How can this code be migrated to support TextKit 2?
3
0
92
Jun ’25
Widget error upon restore iPhone: The file "Name.sqlite" couldn't be opened
I have an app that uses NSPersistentCloudKitContainer stored in a shared location via App Groups so my widget can fetch data to display. It works. But if you reset your iPhone and restore it from a backup, an error occurs: The file "Name.sqlite" couldn't be opened. I suspect this happens because the widget is created before the app's data is restored. Restarting the iPhone is the only way to fix it though, opening the app and reloading timelines does not. Anything I can do to fix that to not require turning it off and on again?
12
0
169
Jun ’25
StoreKit 2: Handle unfinished consumables
I have non-consumable and consumable in-app purchases in my app. The tutorial I was following stated Transaction.currentEntitlements includes unfinished consumables, which is incorrect according to the documentation. Is the correct way to handle unfinished consumables (and non-consumables) to implement Transaction.updates and call finish() if it’s verified? The documentation says that listener will receive unfinished transactions once upon app launch, so with that, do I understand correctly you do not need to implement Transaction.unfinished unless you want to look for unfinished transactions manually later on? Otherwise what is the correct and most recommended way to handle unfinished consumables? Is there a way to test that scenario in Xcode?
1
0
118
Jun ’25
PHAssetChangeRequest revertAssetContentToOriginal without original asset content
The documentation for PHAssetChangeRequest.revertAssetContentToOriginal says it will fail if the original asset content is not on the current device so you should use PHAssetResourceManager to download it first, but this no longer seems to be the case in the latest iOS versions because an error no longer occurs when I take a photo on my iPhone, edit it, open Photos on my iPad and let it sync, then open my app on iPad and call revertAssetContentToOriginal for that asset. Does the system now take care of downloading the original when needed?
1
0
95
Jun ’25