Post

Replies

Boosts

Views

Activity

MKLocalSearch for cities not returning location identities
Hi fellow developers, I'm encountering an issue when using MKLocalSearch to search for cities. Here's my setup: I'm using MKLocalSearch with an MKLocalSearch.Request object. I've set the resultTypes to .address to focus on address results. The problem: When I receive the search response, it includes the locations as expected. However, these locations don't have an identity or alternative identities. Questions: Is this the expected behavior when searching for cities? Without an identity, how can I uniquely identify and store these city results in my database? Would it be appropriate to store the city name, country, and coordinates instead? Thanks in advance!
0
0
68
5d
Crash with any app when switching input method on iOS 18 using iPhone Mirroring
It crashes any app including System Preferences or etc. Below is an example of crash log with my own app. 2024-09-26_15-05-07.3244_+0800-b0897577a4d8c61bb9452bf8ae1f2a0ca097aabc.crash Last Exception Backtrace: 0 CoreFoundation 0x19fa6508c __exceptionPreprocess + 164 (NSException.m:249) 1 libobjc.A.dylib 0x19cd672e4 objc_exception_throw + 88 (objc-exception.mm:356) 2 CoreFoundation 0x19fa29140 -[__NSArrayM objectAtIndexedSubscript:] + 592 (NSArrayM.m:309) 3 UIKitCore 0x1a2fb6554 -[UIInputSwitcherView localizedTitleForItemAtIndex:] + 32 (UIInputSwitcherView.m:860) 4 UIKitCore 0x1a2fbda68 -[UIKeyboardMenuView customizeCell:forItemAtIndex:] + 384 (UIKeyboardMenuView.m:1392) 5 UIKitCore 0x1a2fb68ac -[UIInputSwitcherView customizeCell:forItemAtIndex:] + 88 (UIInputSwitcherView.m:914) 6 UIKitCore 0x1a2fb681c -[UIInputSwitcherView tableView:cellForRowAtIndexPath:] + 192 (UIInputSwitcherView.m:907)
1
0
93
6d
Request .full contacts authorization after being granted .limited
We're adjusting to the new iOS 18 .limited contacts access mode. In our app, we don't request contacts right away. We have a search bar where users can search through their own contacts and select one using the ContactAccessButton. If they do select one, then they're prompted to "Grant Limited Access", not "Grant Full Access", as the screenshot shows below. Later on, we want to offer the ability for users to sync their entire contact book with our app. This will improve their experience on the app by automatically finding all their friends already on the app, without them having to do the manual work of clicking on every single contact in the ContactsAccessPicker. Is this possible right now? It doesn't seem like it—when I call ContactsStore.requestAccess(for: .contacts) while in .limited access mode, nothing happens. But I would like to show a prompt that gives the user the ability to grant all their contacts to improve their experience.
1
0
149
2w
CoreHID HidVirtualDevice Returning Nil
I'm trying to follow the guide for creating a virtual device here. My goal was to see the set report print the data (and to eventually create a virtual gamepad and dispatch input reports of button presses). I am on MacOS v15.0 and I have CoreHID.framework linked (not embedded). However, when using the sample code below, HIDVirtualDevice returns nil. import Foundation import CoreHID // This describes a keyboard device according to the Human Interface Devices standard. let keyboardDescriptor: Data = Data([0x05, 0x01, 0x09, 0x06, 0xA1, 0x01, 0x05, 0x07, 0x19, 0xE0, 0x29, 0xE7, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x08, 0x81, 0x02, 0x95, 0x01, 0x75, 0x08, 0x81, 0x01, 0x05, 0x08, 0x19, 0x01, 0x29, 0x05, 0x95, 0x05, 0x75, 0x01, 0x91, 0x02, 0x95, 0x01, 0x75, 0x03, 0x91, 0x01, 0x05, 0x07, 0x19, 0x00, 0x2A, 0xFF, 0x00, 0x95, 0x05, 0x75, 0x08, 0x15, 0x00, 0x26, 0xFF, 0x00, 0x81, 0x00, 0x05, 0xFF, 0x09, 0x03, 0x75, 0x08, 0x95, 0x01, 0x81, 0x02, 0xC0]) let properties = HIDVirtualDevice.Properties(descriptor: keyboardDescriptor, vendorID: 1) let device = HIDVirtualDevice(properties: properties) final class Delegate : HIDVirtualDeviceDelegate { // A handler for system requests to send data to the device. func hidVirtualDevice(_ device: HIDVirtualDevice, receivedSetReportRequestOfType type: HIDReportType, id: HIDReportID?, data: Data) throws { print("Device received a set report request for report type:\(type) id:\(String(describing: id)) with data:[\(data.map { String(format: "%02x", $0) }.joined(separator: " "))]") } // A handler for system requests to query data from the device. func hidVirtualDevice(_ device: HIDVirtualDevice, receivedGetReportRequestOfType type: HIDReportType, id: HIDReportID?, maxSize: size_t) throws -> Data { print("Device received a get report request for report type:\(type) id:\(String(describing: id))") assert(maxSize >= 4) return (Data([1, 2, 3, 4])) } } if (device != nil) { print("Device is ready") await device?.activate(delegate: Delegate()) try await device?.dispatchInputReport(data: Data([5, 6, 7, 8]), timestamp: SuspendingClock.now) } else { print("Device not created") }
4
0
114
1w
error sharing url on cloudkit share
I'm studying sharing through this link. I followed the first steps by changing the bundle identifier of the project, the tests and placing my own container in the config and in the info.plist. https://github.com/apple/sample-cloudkit-zonesharing The app appears and in the log it appears that it has managed to access my iCloud, but when I click on share and share something, the following message appears in the console, on the simulator and on the iPhone: "No options were found, providing default value for access type" "No options were found, providing default values ​​for permissions" "connection invalidated" And finally, when I click on the shared link, the following message appears: "Item unavailable The owner stopped sharing, or you don't have permission to open it."
0
0
88
5d
SwiftData Document-based app produces strange write errors
I have a document app built using SwiftData because frankly I'm too lazy to learn how to use FileDocument. The app's title is "Artsheets," and I'm using a document type that my app owns: com.wannafedor4.ArtsheetsDoc. The exported type identifier has these values: Description: Artsheets Document Identifier: com.wannafedor4.ArtsheetsDoc Conforms to: com.apple.package Reference URL: (none) Extensions: artsheets MIME Types: (none) And the code: ArtsheetsApp.swift import SwiftUI import SwiftData @main struct ArtsheetsApp: App { var body: some Scene { DocumentGroup(editing: Sheet.self, contentType: .package) { EditorView() } } } Document.swift import SwiftUI import SwiftData import UniformTypeIdentifiers @Model final class Sheet { var titleKey: String @Relationship(deleteRule: .cascade) var columns: [Column] init(titleKey: String, columns: [Column]) { self.titleKey = titleKey self.columns = columns } } @Model final class Column: Identifiable { var titlekey: String var text: [String] init(titlekey: String, text: [String]) { self.titlekey = titlekey self.text = text } } extension UTType { static var artsheetsDoc = UTType(exportedAs: "com.wannafedor4.artsheetsDoc") } I compiling for my iPhone 13 works, but then when creating a document I get this error: Failed to create document. Error: Error Domain=com.apple.DocumentManager Code=2 "No location available to save “Untitled”." UserInfo={NSLocalizedDescription=No location available to save “Untitled”., NSLocalizedRecoverySuggestion=Enable at least one location to be able to save documents.}
8
4
640
Jun ’24
Is it possible to track history using HistoryDescriptor in SwiftData?
Is it possible to track history using the new HistoryDescriptor feature in SwiftData? Or can I only get the current most recent data? Or is it possible to output the changed data itself, along with timestamps? I am hoping that it is possible to track by a standard feature like NSPersistentHistoryTransaction in CoreData. Do we still have to use a method in SwiftData that creates more tracking data itself?
3
0
197
1w
UserDefaults.didChangeNotification not firing
Hi, I'm currently working on an app made originally for iOS 15. On it, I add an observer on viewDidLoad function of my ViewController to listen for changes on the UserDefault values for connection settings. NotificationCenter.default.addObserver(self, selector: #selector(settingsChanged), name: UserDefaults.didChangeNotification, object: nil) Said values can only be modified on the app's section from System Settings. Thing is, up to iOS 17, the notification fired as expected, but starting from iOS 18, the notification doesn't seem to be sent by the OS. Is there anything I should change in my observer, or any other technique to listen for the describe event? Thanks in advance.
1
0
114
6d
Apple Pay on the web P12 key
We created the P12 key from the Merchant ID certificate using KeyChain Access when developing Apple Pay for web. Now we are in the process of deploying Apple Pay to Prod, do we need to generate a new P12 key for Prod? I am not sure about the process here, and need some assistance or understanding. Do I need to create a new P12 for Production deployment or can I use the P12 created when developing? Thanks
0
0
70
5d
PDFKit PDFPage.setBounds(_:for:) returns unexpected results in Xcode16
In XCode15, if you specify mediaBox for PDFDisplayBox, the page will be shrunk to fit the specified range. However, in XCode16, the page is cropped to fit the specified range, as when cropBox is specified for PDFDisplayBox. I think it's a bug because the setBounds documentation hasn't been updated, but has anyone had the same problem? Please let me know if there are any workarounds.
0
0
116
1w
poll(2) slower than select(2)
I have a program that creates a TCP server socket and listens on it. When the program accepts a connection from a client, it calls poll(2) repeatedly to see if there is any input available, like this: for (int i = 0; i < 1000000; i++) { struct pollfd fds[] = {{ .fd = clientfd, .events = POLLIN, .revents = 0 }}; int r = poll(fds, 1, 0); if (r < 0) { perror("poll"); exit(1); } } On my Intel iMac, this takes about 15 seconds. If I use select(2) instead, as follows, it takes about 550ms. for (int i = 0; i < 1000000; i++) { struct timeval timeout = { .tv_sec = 0, .tv_usec = 0 }; fd_set infds; FD_ZERO(&infds); FD_SET(clientfd, &infds); int r = select(1, &infds, 0, 0, &timeout); if (r < 0) { perror("select"); exit(1); } } https://gist.github.com/xrme/cd42d3d753ac00861e439e012366f2cf is a C source file that contains a complete example. If you're inclined to take a look, please download the file from the gist and do cc poll-test.c and then ./a.out. Connect to it with nc 127.0.0.1 6444 and observe that it will take quite a while. (Activity Monitor will show a large number of "idle wake ups", but I'm not clear what that signifies.) Recompile with cc -DUSE_SELECT, run ./a.out and connect again, and it will complete in under a second. Advisability of this usage aside (which is adapted from a much larger system), is there anything here to be done to make poll faster? Other systems I have looked at (FreeBSD, OmniOS, Linux) do not exhibit the same slowdown with poll.
2
0
109
6d
Usb Keyboard will wake up the system when sending command to it at system start to sleep
Development environment: Electron 30.2.0 Run-time configuration: macOS 14.5 (23F79) DESCRIPTION OF PROBLEM I have one keyboard which will wake up the Mac OS from sleep when sending command to it at the time system starting to sleep. But this keyboard will not have such problem on Window OS, I don't know why sending command to that keyboard will wake up the Mac OS system from sleep. Does anyone know from a hardware or software point of view, what kind of usb keyboard operation will cause the macos system to wake up? Or can someone give us guidance, how to debug and solve the usb keyboard caused by the wake up system problem on Mac OS system? STEPS TO REPRODUCE Sending command to that keyboard when the system start to sleep
0
0
30
6d
Sequoia, multicast and lldb - no route to host
On Sequoia it became impossible to properly debug programs using third party mDNS, multicast or broadcast, thanks to a bug? in I guess the new local network privacy feature, every send call returns no route to host. If I run the CI job, which properly packages, signs, notarizes said program, the resulting .app works fine and also requests permission to access the local network - which is impossible through lldb as it doesn't have an Info.plist, just the ***** binary itself. However this may not be the issue, see the repro method below. A fast and easy method to reproduce is using an example from this repo: https://github.com/keepsimple1/mdns-sd/ Running the query example in a good old shell without lldb (cargo run --example query _smb._tcp) starts outputting results. Then running the same binary through lldb (lldb -o run target/debug/examples/query _smb._tcp) would result in no route to host errors. I can't provide an output anymore as I was forced to downgrade. It works fine again on 14.6.1. I'm a bit reluctant to even try 14.7. Also reported in feedback assistant: FB15185667
4
1
185
1w
Question regards thread safety for Dispatch queue and Network Framework completion callbacks
Hi there, I have some thread related questions regards to network framework completion callbacks. In short, how should I process cross thread data in the completion callbacks? Here are more details. I have a background serial dispatch queue (call it dispatch queue A) to sequentially process the nw_connection and any network io events. Meanwhile, user inputs are handled by serial dispatch queue ( dispatch queue B). How should I handle the cross thread user data in this case? (I write some simplified sample code below) struct { int client_status; char* message_to_sent; }user_data; nw_connection_t nw_connection; dispatch_queue_t dispatch_queue_A static void send_message(){ dispatch_data_t data = dispatch_data_create(message, len(message), dispath_event_loop->dispatch_queue, DISPATCH_DATA_DESTRUCTOR_DEFAULT); nw_connection_send( nw_connection, data, NW_CONNECTION_DEFAULT_MESSAGE_CONTEXT, false, ^(nw_error_t error) { user_data.client_status = SENT; mem_release(user_data.message_to_sent); }); }); } static void setup_connection(){ dispatch_queue_A= dispatch_queue_create("unique_id_a", DISPATCH_QUEUE_SERIAL); nw_connection = nw_connection_create(endpoint, params); nw_connection_set_state_changed_handler(){ if (state == nw_connection_state_ready) { user_data.client_status = CONNECTED } // ... other operations ... } nw_connection_start(nw_connection); nw_retain(nw_connection); } static void user_main(){ setup_connection() user_data.client_status = INIT; dispatch_queue_t dispatch_queue_B = dispatch_queue_create("unique_id_b", DISPATCH_QUEUE_SERIAL); // write socket dispatch_async(dispatch_queue_B, ^(){ if (user_data.client_status != CONNECTED ) return; user_data.message_to_sent = malloc(XX,***) // I would like to have all io events processed on dispatch queue A so that the io events would not interacted with the user events dispatch_async_f(dispatch_queue_A, send_message); // Disconnect block dispatch_async(dispatch_queue_B, ^(){ dispatch_async_f(dispatch_queue_A, ^(){ nw_connection_cancel(nw_connection) }); user_data.client_status = DISCONNECTING; }); // clean up connection and so on... } To be more specific, my questions would be: As I was using serial dispatch queue, I didn't protect the user_data here. However, which thread would the send_completion_handler get called? Would it be a data race condition where the Disconnect block and send_completion_handler both access user_data? If I protect the user_data with lock, it might block the thread. How does the dispatch queue make sure it would NOT put a related execution block onto the "blocked thread"?
4
0
123
1w
Live activity sample code for Swift 6?
Hi, I'm updating our app to use Xcode 16 and Swift 6 language mode. I'm stuck on updating our live activity code. I looked at the Emoji Rangers sample project and after switching it to Swft 6 mode, it has the exact same errors as our project. The main problem seems to be that Activity is not Sendable, which prevents us from passing it to child tasks to await things like activityStateUpdates and contentUpdates (those are also not Sendable). Is there any guidance on this? Updated sample code? Another project?
4
0
150
1w
Swift 6 and NSPersistentCloudKitContainer
Hello all! I'm porting a ios15+ swiftui app to be compatible with Swift 6 and enabling strict concurrency checking gave me a warning that will be an error when switching to swift 6. I'm initializing a persistence controller for my cloud kit container: import CoreData struct PersistenceController { static let shared = PersistenceController() let container: NSPersistentCloudKitContainer init() { container = NSPersistentCloudKitContainer(name: "IBreviary") container.loadPersistentStores(completionHandler: { _, error in if let error = error as NSError? { fatalError("Unresolved error \(error), \(error.userInfo)") } }) container.viewContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy container.viewContext.automaticallyMergesChangesFromParent = true } } The warning is on the merge policy: Reference to var 'NSMergeByPropertyObjectTrumpMergePolicy' is not concurrency-safe because it involves shared mutable state; this is an error in the Swift 6 language mode I have no idea how to make this concurrency safe, nor I found a documentation entry to help me with this. Anyone have idea how to solve this? Thanks in advance V.
2
0
150
6d
AppTransaction: how to use in ObjC apps (now that we are forced to use it after the exit(173) deprecation)
Hello We are developers of a long-running game series and now reports have started to come in that users who install any of our previous games from the Mac App Store on OS X Sequoia are shown a popup claiming "The exit(173) API is no longer available". It's actually a lie, the mechanism is still there, the receipt generation still works and the game still runs afterwards. But the popup is confusing to users therefore we need to update the code. Apparently the replacement for the old receipt generation mechanism is AppTransaction which does not exist for Objective C. We have attempted to use it using the Swift/ObjC interoperability and failed so far. The problem is that we need to call async methods in AppTransaction and all our attempts to make this work have failed so far. It seems as the actor/@MainActor concept is not supported by Swift/ObjC interoperability and without those concepts we don't know how to pass results from the async context to the callers from ObjC. The lack of usable information and code online regarding this topic is highly frustrating. Apple really needs to provide better support for developers if they want us to continue to support the Mac platform with high quality games and applications on the Mac App Store. We would appreciate if anyone can cook up a working sample code how to use AppTransaction in ObjC. Thanks in advance!
6
0
155
1w
Network Framework Broadcast Support
Hi all, I am overhauling code of an iPadOS app that discovers devices on a network using a custom UDP broadcast based discovery protocol. This is how the discovery mechanism should work: The iPad sends an IPv4 broadcast message to the network's broadcast address using a fixed destination port, but a random source port (determined at bind time). The device responds with a unicast message to the source IP address and port of the discovery message. Until now the code is based on BSD sockets using GCDAsyncUdpSocket and has been working well for around ten years with a single socket that was used to both send and receive the discovery messages and replies. We would like to make the move to the Network Framework now and I tried to recreate this discovery mechanism with the Network Framework in Objective-C. I am able to create an nw_connection_t with the broadcast address as hostname and the specific destination port as port. I am able to send discovery messages to the device and the device sends a reply (verified with Wireshark). But calling nw_connection_receive_message(...) never fires. Also in Wireshark the iPad replies with Destination unreachable (Port unreachable). When I create the connection with the unicast address of the device, the reply is received. It seems to me, that the connection doesn't accept replies from addresses / ports that don't match, what was set when the connection was created. Is there a way to also accept messages from other sources? E.g. there is nw_multicast_group_descriptor_set_disable_unicast_traffic when doing multicast. This seems to solve this problems when doing mutlicast. This is a code excerpt of what I tried: // Create default UDP parameters without DTLS nw_parameters_t params = nw_parameters_create_secure_udp(NW_PARAMETERS_DISABLE_PROTOCOL, NW_PARAMETERS_DEFAULT_CONFIGURATION); // Enable P2P (should enable broadcast and multicast) nw_parameters_set_include_peer_to_peer(params, true); // Require the active interface // The active interface comes from a path monitor callback nw_parameters_require_interface(params, self.networkUtils.activeInterface.interface); // Setup the remote endpoint with the "ping" (discovery) broadcast IP address and port const char *endpointAddress = [pingAddress.ipAddress cStringUsingEncoding:NSUTF8StringEncoding]; NSString *portString = @(pingAddress.port).stringValue; const char *endpointPort = [portString cStringUsingEncoding:NSUTF8StringEncoding]; nw_endpoint_t broadcastEndpoint = nw_endpoint_create_host(endpointAddress, endpointPort); nw_connection_t tmpConnection = nw_connection_create(broadcastEndpoint, params); __weak __typeof(self) weakSelf = self; nw_connection_set_state_changed_handler(tmpConnection, ^(nw_connection_state_t state, nw_error_t _Nullable error) { __strong __typeof(weakSelf) strongSelf = weakSelf; MSLogVerbose("State changed: %d; error: %@", state, error); strongSelf.connectionState = state; if (state == nw_connection_state_ready) { [strongSelf receiveMessageForConnection:tmpConnection]; } }); nw_connection_set_queue(tmpConnection, AGGalileoBrowser.browserQueue); nw_connection_start(tmpConnection); Thanks for your help! Arno
3
0
112
1w