Post

Replies

Boosts

Views

Activity

Can't obtain the user's Apple Music token on macOS (Catalyst)
On a macOS app generated with Catalyst, the method SKCloudServiceController.requestUserToken(forDeveloperToken:completionHandler:) returns a SKErrorDomain. The error is: Error Domain=SKErrorDomain Code=0 "Ocorreu um erro desconhecido" UserInfo={NSLocalizedDescription=Ocorreu um erro desconhecido} Has something changed regarding this method on macOS or is this a bug?
9
0
2.3k
Dec ’21
Assign a category name to the Find intent generated by EntityPropertyQuery
In an AppIntent we can declare an IntentDescription with a categoryName to group similar intents: struct OpenArtist: AppIntent { static var description: IntentDescription = IntentDescription("Opens a specific artist.", categoryName: "artistsSection") // Additional properties } But how can we assign the same category to the "Find AppEntity" intent generated when we declare an EntityPropertyQuery? I want to group it along with the other intents that handle the same entity, but since it is generated by the system, I don't know how to assign a category to it.
2
2
1.5k
Mar ’23
App Groups capability is not available for Mac Catalyst provisioning profile
I'm trying to build my iOS app to macOS Catalyst. Everything works fine when running locally on my machine via Xcode, but an error occurs when I archive and try to upload to the notarisation service: Cannot create a Mac Catalyst Developer ID provisioning profile for "br.com.marcosatanaka.music-harbor". The App Groups capability is not available for Mac Catalyst Developer ID provisioning profiles. Disable this feature and try again. I have the App Groups capability enabled on my app's target Signing & Capabilities tab on Xcode. But, when I go to the Apple Developer portal under Certificates, Identifiers & Profiles > Profiles and select the Mac Catalyst provisioning profile (automatically generated by Xcode), the App Groups capability is not present on the Enabled Capabilities section. I can work around this issue by removing the com.apple.security.application-groups entitlement when building for Mac Catalyst, but that causes me a runtime error when Core Data tries to access the store located on the shared container. I also need it to be on a shared container because I want to access the database from both the main app and also the new widget extension. How can I add the App Groups capability to my Mac Catalyst provisioning profile?
5
0
15k
Jul ’22
UICommand is disabled on UIMenu inside NSMenuToolbarItem.itemMenu on Catalyst
Before beta 4 this worked as expected. After updating to beta 4, all my UICommands inside UIMenu on NSMenuToolbarItem.itemMenu are now disabled, and I can't figure out how to enable them. Here's my itemForItemIdentifier method: func toolbar(_ toolbar: NSToolbar, itemForItemIdentifier itemIdentifier: NSToolbarItem.Identifier, willBeInsertedIntoToolbar flag: Bool) -> NSToolbarItem? { 		let item = NSMenuToolbarItem(itemIdentifier: itemIdentifier) 		item.itemMenu = UIMenu(title: "", options: .displayInline, children: [UICommand(title: "Test", action: #selector(onTestTap))]) 		item.image = UIImage(systemName: "ellipsis.circle") 		return item } Am I doing something wrong or is this a bug on macOS Big Sur beta 4?
5
0
2k
Apr ’21
Transaction.latest(for:) returns nil in StoreKit 2
Using the Implementing a Store In Your App Using the StoreKit API sample code, I've successfully integrated my new APP with StoreKit 2. There is one problem though: when I call the method Transaction.latest(for:) to get the user’s latest transaction, it always returns nil. Here's the code snippet: guard let result = await Transaction.latest(for: myProductId) else { return false } Is this a bug with StoreKit 2, or am I doing something wrong? This happens on a physical device, running from Xcode. Thanks in advance.
4
0
2.2k
Jan ’22
Shortcuts editor doesn't recognize boolean EntityQueryProperty
My AppEntity has a Bool property, and I would like to query by this property using EntityPropertyQuery. I'm creating an EntityQueryProperty for it with an EqualToComparator as the following (partial code for brevity): // My AppEntity struct AlbumAppEntity: AppEntity, Identifiable { @Property(title: "Hidden") var isHidden: Bool // Other properties } // My EntityPropertyQuery static var properties = QueryProperties { Property(\AlbumAppEntity.$isHidden) { EqualToComparator { isHidden in if isHidden { return NSPredicate(format: "isHidden == YES") } else { return NSCompoundPredicate(type: .or, subpredicates: [NSPredicate(format: "isHidden = nil"), NSPredicate(format: "isHidden == NO")]) } } } } But the problem is that Shortcuts does not recognize it as a boolean parameter in the shortcuts editor. It recognizes it as a numeric field, which returns the error AppIntents.EntityPropertyQueryError error 2 when run: I also tried different NSPredicate, but the result is always the same: Property(\AlbumAppEntity.$isHidden) { EqualToComparator { NSPredicate(format: "isHidden == %d", $0) } } Property(\AlbumAppEntity.$isHidden) { EqualToComparator { NSPredicate(format: "isHidden == %@", NSNumber(value: $0)) } } How can I query using boolean properties in a way that Shortcuts recognizes it and provides appropriate fields in the shortcuts editor?
0
1
1.3k
Aug ’22
Opening a Safari URL from an interactive widget with AppIntents
My app allows users to store URLs for future reference. It also has widgets that display these saved items. I want to make these widgets interactive by opening the linked content in Safari without having to open the main app. The issue is that UIApplication.shared.open is not available in app extensions. And this is a problem since widgets are app extensions. Are there alternative methods to accomplish this scenario, or is it currently unsupported?
1
1
1.5k
Jul ’23
openAppWhenRun makes AppIntent crash when launched from Control Center.
Adding the openAppWhenRun property to an AppIntent for a ControlWidgetButton causes the following error when the control is tapped in Control Center: Unknown NSError The operation couldn’t be completed. (LNActionExecutorErrorDomain error 2018.) Here’s the full ControlWidget and AppIntent code that causes the errorerror: Should controls be able to open apps after the AppIntent runs, or is this a bug?
5
2
3.0k
Sep ’24
Can’t focus the sidebar on tvOS when TabView contains TabSection elements
In a TabView with the .sidebarAdaptable style, including TabSection elements prevents the default back swipe on the remote from revealing the sidebar. Removing all TabSection elements and using only Tab elements makes it work as expected: import SwiftUI struct ContentView: View { var body: some View { TabView { Tab("Tab", systemImage: "square.fill") { Button(action: {}) { Text("Button") } } Tab("Tab", systemImage: "square.fill") { Button(action: {}) { Text("Button") } } Tab("Tab", systemImage: "square.fill") { Button(action: {}) { Text("Button") } } Tab("Tab", systemImage: "square.fill") { Button(action: {}) { Text("Button") } } Tab("Tab", systemImage: "square.fill") { Button(action: {}) { Text("Button") } } Tab("Tab", systemImage: "square.fill") { Button(action: {}) { Text("Button") } } Tab("Tab", systemImage: "square.fill") { Button(action: {}) { Text("Button") } } Tab("Tab", systemImage: "square.fill") { Button(action: {}) { Text("Button") } } Tab("Tab", systemImage: "square.fill") { Button(action: {}) { Text("Button") } } TabSection("Section") { Tab("Tab", systemImage: "square.fill") { Button(action: {}) { Text("Button") } } Tab("Tab", systemImage: "square.fill") { Button(action: {}) { Text("Button") } } } }.tabViewStyle(.sidebarAdaptable) } } Am I using it wrong, or is this a bug?
3
2
834
Jan ’25
SwiftUI: How to change List selected item color
iPadOS uses a different selection color when an external keyboard is connected. But the problem is that it doesn't change the text color to white, making it difficult to read: A simple List with NavigationLink produces this behavior by default: var body: some View { List { ForEach(searchResults) { item in NavigationLink(destination: ContentDetailView(item: item)) { ListItemView(item: item) } } } } I tried to improve text legibility by changing all Text colors to white when the cell is selected. But this doesn't work because the text becomes even more unreadable when no external keyboard is connected. Is there a way to change the selection color when an external keyboard is connected? Or maybe detect when an external keyboard is connected to manually change the text color for this specific case?
0
1
1.4k
Mar ’22
How to sort my Core Data entities using the new query properties from AppIntents
TL;DR How to create an NSSortDescriptor using a PartialKeyPath instead of a KeyPath? Or How to convert a PartialKeyPath to a KeyPath? Details I'm using the new query properties from AppIntents to filter my app's data in Shortcuts, but I'm unable to map the sorting attribute it gives me to the sorting attribute Core Data expects in the predicate. Here's my EntityPropertyQuery implementation: extension ArtistQuery: EntityPropertyQuery { static var sortingOptions = SortingOptions { SortableBy(\ArtistEntity.$name) } static var properties = QueryProperties { Property(\ArtistEntity.$name) { EqualToComparator { NSPredicate(format: "name = %@", $0) } ContainsComparator { NSPredicate(format: "name CONTAINS %@", $0) } } } func entities(matching comparators: [NSPredicate], mode: ComparatorMode, sortedBy: [Sort<ArtistEntity>], limit: Int?) async throws -> [ArtistEntity] { Database.shared.findArtists(matching: comparators, matchAll: mode == .and, sorts: sortedBy.map { NSSortDescriptor(keyPath: $0.by, ascending: $0.order == .ascending) }) } } And my findArtists method is implemented as follows: static func findArtists(matching comparators: [NSPredicate], matchAll: Bool, sorts: [NSSortDescriptor]) -> [EArtist] { ... } As we can see in the entities(matching:) function, I'm using the by attribute from the sortedBy parameter to create the NSSortDescriptor, but it doesn't work because the NSSortDescriptor init expects a KeyPath, not a PartialKeyPath: Cannot convert value of type 'PartialKeyPath<ArtistEntity>' to expected argument type 'KeyPath<Root, Value>' So, can I create an NSSortDescriptor using a PartialKeyPath instead of a KeyPath? Or maybe converting a PartialKeyPath to a KeyPath?
1
1
1.7k
Aug ’22
CloudKit causes SwiftUI Menu to be dismissed
After updating to iOS 17 and Xcode 15 I noticed that menus on my app get automatically dismissed while CloudKit is syncing data right after opening the app. I know it's CloudKit because this issue doesn't happen when I launch the app in Airplane Mode. It looks like CloudKit causes something to change (even when there are no data changes since the last usage), which causes the UI to refresh. This refresh causes the menus to be dismissed. This is frustrating because users have to tap a button two or three times before being able to interact with the menu showed by the button. I'm attaching a screen recording that shows the issue: https://youtube.com/shorts/Wl9gP2HLktE I open the app and tap the "+" icon, which shows the menu. The menu is quickly dismissed. I tap the "+" icon again, and the menu is shown for a millisecond, and is dismissed again. I tap the "+" button once again. This time the menu is shown and stays there because CloudKit has finished its initial sync process. Note that this didn't happened on iOS 16 / Xcode 14, so something must have changed to cause this issue. Is there something I need to update on my code to fix this issue, or is it a bug in the OS or frameworks that will be fixed in a future update?
2
1
930
Oct ’23
translationTask does not execute when content appears
The documentation for translationTask(source:target:action:) says it should translate when content appears, but this isn't happening. I’m only able to translate when I manually associate that task with a configuration, and instantiate the configuration. Here’s the complete source code: import SwiftUI import Translation struct ContentView: View { @State private var originalText = "The orange fox jumps over the lazy dog" @State private var translationTaskResult = "" @State private var translationTaskResult2 = "" @State private var configuration: TranslationSession.Configuration? var body: some View { List { // THIS DOES NOT WORK Section { Text(translationTaskResult) .translationTask { session in Task { @MainActor in do { let response = try await session.translate(originalText) translationTaskResult = response.targetText } catch { print(error) } } } } // THIS WORKS Section { Text(translationTaskResult2) .translationTask(configuration) { session in Task { @MainActor in do { let response = try await session.translate(originalText) translationTaskResult2 = response.targetText } catch { print(error) } } } Button(action: { if configuration == nil { configuration = TranslationSession.Configuration() return } configuration?.invalidate() }) { Text("Translate") } } } } } How can I automatically translate a given text when it appears using the new translationTask API?
3
1
1.1k
Aug ’24
onContinueUserActivity(CSSearchableItemActionType, perform) does not work on a SwiftUI macOS app
onContinueUserActivity(CSSearchableItemActionType, perform) works as expected on iOS when we search and select an item from Spotlight, but nothing happens when we do the same on a SwiftUI macOS app. var body: some Scene { WindowGroup { MyView() .onContinueUserActivity(CSSearchableItemActionType, perform: handleSpotlight) } } func handleSpotlight(_ userActivity: NSUserActivity) { // Is not called... } How can we respond to a user clicking a Spotlight result from our apps on macOS?
3
1
894
Oct ’25