Post

Replies

Boosts

Views

Activity

Sync SwiftData via CloudKit on App Start
I have an app that uses SwiftData with CloudKit to synchronize data across a users devices. I'm able to replicate data created on one device on another and when removing data, it is also removed on the other device. So, I know that SwiftData and CloudKit are configured correctly. What I'd like to do though, is to ensure that if a user installs the app on an additional device, that the data is synchronized upon app start. When testing my app on a third device, via TestFlight, there was no data in the app upon launch even though all three devices are using the same Apple account (e.g. Apple ID). What is the best way to achieve this?
4
1
113
6d
Background fetching data not work
Hello, I have a some problem with background fetch. In my app I use background modes for fetch data and display on my home widget iPhone. Its working correct when I built app on my phone from Xcode but when I distribute my app on TestFlight my home widget not updating at all. Help me understand if this issue is only due to TestFlight resources, or should I try releasing the app and hope that it will work in the release version?
1
0
156
5d
Contacts: remove member from group not working on macOS
Hi, In my app, I have an option to remove a contact from a contact group (using the Contacts framework), and it's been working fine till recently users of the macOS version reported that it's not working. I have been using the CNSaveRequest removeMember(contact, from: group) API. The same API works fine on iOS. I'm not sure when it started but it seems to be affecting macOS14.6 as well as 15.1. I was able to reproduce it in a small test project as well, and have the same experience (the API works on iOS but not on macOS), so it definitely seems like a problem with the framework. Can someone confirm this, and/or suggest a workaround? Here's the code I run to test it out ...a simple SwiftUI view that has 4 buttons: Create contact and group Add contact to group Remove contact from group (optional) cleanup by deleting contact and group It's the 3rd step that seems to fail on macOS, but works fine on iOS. Here's the code to test it out: struct ContentView: View { let contactsModel = ContactsStoreModel() var body: some View { VStack (alignment: .center, spacing: 15){ Button ("1. Add Contact And Group") { print("add contact button pressed") contactsModel.addTestContact() if let _ = contactsModel.createdContact { print("created contact success") } } Button ("2. Add Contact To Group") { print("add to group button pressed") contactsModel.addContactToGroup() } Button ("3. Remove Contact From Group") { print("remove from group button pressed") contactsModel.removeContactFromGroup() } Button ("4. Delete Contact and Group") { print("remove from group button pressed") contactsModel.deleteContactAndGroup() } } .padding() } } #Preview { ContentView() } @available(iOS 13.0, *) @objc final class ContactsStoreModel: NSObject, ObservableObject { let contactStore = CNContactStore() var createdContact : CNContact? var createdGroup : CNGroup? public func addTestContact() { let storeContainer = contactStore.defaultContainerIdentifier() let contact = CNMutableContact() contact.givenName = "Testing" contact.familyName = "User" contact.phoneNumbers = [CNLabeledValue(label: "Cell", value: CNPhoneNumber(stringValue: "1234567890"))] let group = CNMutableGroup() group.name = "Testing Group" print("create contact id = \(contact.identifier)") print("create group id = \(group.identifier)") do { let saveRequest = CNSaveRequest() saveRequest.transactionAuthor = "TestApp" saveRequest.add(contact, toContainerWithIdentifier: storeContainer) saveRequest.add(group, toContainerWithIdentifier: storeContainer) try contactStore.execute(saveRequest) createdContact = contact createdGroup = group } catch { print("error in store execute = \(error)") } } public func addContactToGroup() { if let contact = createdContact, let group = createdGroup { do { let saveRequest = CNSaveRequest() saveRequest.transactionAuthor = "TestApp" saveRequest.addMember(contact, to: group) try contactStore.execute(saveRequest) } catch { print("error in store execute = \(error)") } } } public func removeContactFromGroup() { if let contact = createdContact, let group = createdGroup { do { let saveRequest = CNSaveRequest() saveRequest.transactionAuthor = "TestApp" saveRequest.removeMember(contact, from: group) try contactStore.execute(saveRequest) } catch { print("error in store execute = \(error)") } } } public func addGroupAndContact() { let storeContainer = contactStore.defaultContainerIdentifier() let group = CNMutableGroup() group.name = "Test Group" print("create group id = \(group.identifier)") if let contact = createdContact { do { let saveRequest = CNSaveRequest() saveRequest.transactionAuthor = "TestApp" saveRequest.add(group, toContainerWithIdentifier: storeContainer) saveRequest.addMember(contact, to: group) try contactStore.execute(saveRequest) createdGroup = group } catch { print("error in store execute = \(error)") } } } public func deleteContactAndGroup() { if let contact = createdContact, let group = createdGroup { do { let mutableGroup = group.mutableCopy() as! CNMutableGroup let mutableContact = contact.mutableCopy() as! CNMutableContact let saveRequest = CNSaveRequest() saveRequest.transactionAuthor = "TestApp" saveRequest.delete(mutableContact) saveRequest.delete(mutableGroup) try contactStore.execute(saveRequest) } catch { print("error in deleting store execute = \(error)") } } } }
0
0
68
4d
NWConnection and "Network is Down" error connecting to ip address and port
I have a pretty straightforward code to connect to a given ip address and port using NWConnection. On the first attempt to connect to the Local Network I see the "Local Network Privacy" dialog and sometimes if I press "Don't Allow" on that dialog everything starts to fail. No matter I do I keep receiving the following error: POSIXErrorCode(rawValue: 50): Network is down Obviously going to settings and allowing local network access to the app doesn't fix the issue. Neither deleting the app and installing it again. The only workaround I found is to restart my device which is unacceptable for a user. My code is really simple, I tried a lot of different approaches to connect but neither approach worked. I am on iOS 18. Is it a known bug? could be possible a bug on my code? Any idea would be really appreciated, thanks!
8
2
201
1w
How to completely reset SwiftData?
Is it possible to reset SwiftData to a state identical to that of a newly installed app? I have experienced some migration issues where, when I add a new model, I need to reinstall the entire application for the ModelContainer creation to work. Deleting all existing models does not seem to make any difference. A potential solution I currently have, which appears to work but feels quite hacky, is as follows: let _ = try! ModelContainer() modelContainer = try! ModelContainer(for: Student.self, ...) This seems to force out this error CoreData: error: Error: Persistent History (66) has to be truncated due to the following entities being removed: (...) which seems to reset SwiftData. Any other suggestions?
2
0
101
5d
Swiftdata + Cloudkit + Mac OS how to configure for existing Swift Data store
Hi, I have a mac os app that I am developing. It is backed by a SwiftData database. I'm trying to set up cloudkit so that the app's data can be shared across the user's devices. However, I'm finding that every tutorial i find online makes it sound super easy, but only discusses it from the perspective of ios. The instructions typically say: Add the iCloud capability. Select CloudKit from its options. Press + to add a new CloudKit container, or select one of your existing ones. Add the Background Modes capability. Check the box "Remote Notifications" checkbox from its options. I'm having issue with the following: I don't see background modes showing up or remote notifications checkbox since i'm making a mac os app. If i do the first 3 steps only, when i launch my app i get an app crash while trying to load the persistent store. Here is the exact error message: Add the iCloud capability. Select CloudKit from its options. Press + to add a new CloudKit container, or select one of your existing ones. Add the Background Modes capability. Check the box "Remote Notifications" checkbox from its options. Any help would be greatly appreciated. var sharedModelContainer: ModelContainer = { let schema = Schema([One.self, Two.self]) let modelConfiguration = ModelConfiguration(schema: schema, isStoredInMemoryOnly: false) do { return try ModelContainer(for: schema, configurations: [modelConfiguration]) } catch { fatalError("Could not create ModelContainer: \(error)") } }() The fatal error in the catch block happens when i run the app.
7
0
454
Oct ’24
continue UserActivity in AppDelegate not working after firing completion(INSendPaymentIntentResponse(code: .failureRequiringAppLaunch, userActivity: userActivity ))
func handle(intent: INSendPaymentIntent, completion: @escaping (INSendPaymentIntentResponse) -> Void) { if let _ = intent.payee, let currencyAmount = intent.currencyAmount { let userActivity = NSUserActivity(activityType: "com.rapipay.nye.test.failure") userActivity.userInfo = ["amount": Int(truncating: currencyAmount.amount!)] completion(INSendPaymentIntentResponse(code: .failureRequiringAppLaunch, userActivity: userActivity )) return } } func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([any UIUserActivityRestoring]?) -> Void) -> Bool { print("ddddd") return true } this code is perfectly working on simulator and even i fi user userActivity as nil, continue userActivity is called, but on device it is not called Siri is working, asking for name and amount and handler is also called and opens app but does not pass intent or userActivity
7
0
263
Oct ’24
Does iOS Automatically Reconnect to Disconnected BLE Devices, or Is It App-Driven?
Does iOS Automatically Reconnect to Disconnected BLE Devices, or Is It App-Driven? I have a few questions regarding BLE device reconnections in iOS: When a BLE device gets disconnected, does iOS automatically attempt to reconnect to it, or is it the app’s responsibility to handle the reconnection logic? If the app doesn’t initiate a BLE scan, will the OS still attempt to reconnect to previously paired devices, or is manual intervention by the app necessary? What is the recommended approach to re-establish a BLE connection when: The app has been deleted. The BLE device remains connected in the iPhone's Bluetooth settings. The app is reinstalled later. Any insights or best practices would be greatly appreciated!
0
0
52
5d
Failure during payment with sandbox account
I got this error if I buy my IAP on the simulator with a sandbox account. Any solutions? On android it's working very well. <SKPaymentQueue: 0x6000018b8430>: Payment completed with error: Error Domain=ASDErrorDomain Code=530 "(nu11)" UserInfo={NSUnderlyingError=0x600001512970 (Error Domain=AMSErrorDomain Code=100 "Authentication Failed The authentication failed." UserInfo={NSMultipleUnderlyingErrorsKey=( "Error Domain=AMSErrorDomain Code=2 \"Password reuse not available for account The account state does not support password reuse.\" UserInfo={NSDebugDescription=Password reuse not available for account The account state does not support password reuse., AMSDescription=Password reuse not available for account, AMSFailureReason=The account state does not support password reuse.}", "Error Domain=AMSErrorDomain Code=0 \"Authentication Failed Encountered an unrecognized authentication failure.\" UserInfo={NSDebugDescription=Authentication Failed Encountered an unrecognized authentication failure,, AMSDescription=Authentication Failed, AMSFailureReason=Encountered an unrecognized authentication failure,}" ), AMSDescription=Authentication Failed, NSDebugDescription=Authentication Failed The authentication failed., AMSFailureReason=The authentication failed,}}, storefront-country-code=USA, client-environment-type=Sandbox)
2
0
146
6d
Focus more evolved
This message only to know your feeling on my project. Not to discuss what is feasible or not. Just on the interest of the functionality. I use 5 Focus profiles, Do Not Disturb, Holiday, Work, Personal and Sleep. I find that the native solutions for changing modes are not powerful enough. I'd like an app to configure automatically when each Focus profile should be activated. Eg : -Holiday : when holiday is found in my calendar -Work : when I'm not on holiday, when we are not on the weekend, and after 7ham but before 7pm. Personal : when I'm not on holiday when we are on the weekend of after 7pm -Dot Not Disturb: When I'm not in holiday, only on the working week when I have an event in my agenda with the status accepted". These are just some examples. the idea is that everything will be configurable. (my app is almost finished.) What do you think?
0
0
83
5d
Should I prepare to Apple renewal of APNs USERTrust RSA Certification Authority certificate?
On apple dev site in the news section here you can find two announcements about their renewal of: USERTrust RSA Certification Authority certificate. Context: now, I have an app delivered via in-house distribution due to Apple developer Enterprise program. My app uses push notifications, but we are using auth tokens. Should I do something on the app? Should I advice backend colleague to check or do something server-side? below you can find the two announcements: sanbox link APNs Certificate Update Begins January 20, 2025 The Apple Push Notification service (APNs) will be updated with a new server certificate in sandbox on January 20, 2025. Update your application’s Trust Store to include the new server certificate: SHA-2 Root : USERTrust RSA Certification Authority certificate. and production link APNs Certificate Update Begins February 24, 2025 The Apple Push Notification service (APNs) will be updated with a new server certificate in production on February 24, 2025. Update your application’s Trust Store to include the new server certificate: SHA-2 Root : USERTrust RSA Certification Authority certificate.
0
0
72
5d
MacOS CloudKit production environment is not working properly
My macOS app is developed using SwfitUI, SwiftData, and CloudKit. In the development environment, CloudKit works well. Locally added models can be quickly viewed in the CloudKit Console. macOS app and iOS app with the same BundleID can also synchronize data normally when developing locally. However, in the production environment, the macOS app cannot synchronize data with iCloud. But iOS app can. The models added in the production environment are only saved locally and cannot be viewed in CloudKit Console Production. I am sure I have configured correctly, container schema changes to deploy to the Production environment. I think there may be a problem with CloudKit in macOS. Please help troubleshoot the problem. I can provide you with any information you need. var body: some Scene { WindowGroup { MainView() .frame(minWidth: 640, minHeight: 480) .environment(mainViewModel) } .modelContainer(for: [NoteRecord.self]) } I didn't do anything special. I didn’t do anything special. I just used SwiftData hosted by CloudKit.
2
0
133
1w
Query regarding transparent proxy provider NENetworkRule for port 53
We want to ressolve dns for predefined sets of private app domains. We've added this rule: NENetworkRule(destinationHost: NWHostEndpoint(hostname: Private Domain1(example.com), port: 53), protocol: .UDP) As per apple documentation: A rule that matches all DNS queries/responses for hosts in the example.com domain. do you think it will work i.e it will forward DNS requests UDP flow to transparent provider in all the cases? or do you think the text is a bit misleading. it should instead say: "A rule that matches all DNS queries/responses for nameservers in the example.com domain"? This rule that look for port 53 of that domain only works if the system really asks a nameserver of that specific domain, right? So, what if a local DNS server or a different nameserver are taking care of the resolution?
3
0
123
5d
iOS Socket cannot connect ipv6 address when use PacketTunnelProvider
I'm use iPad OS 17.5.1, when I try to use socket to connect to an ipv6 address created by PacketTunnelProvider in my iOS device, an error occurs. Here is the code to create socket server and client: #include <stdio.h> #include <string.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <unistd.h> int dx_create_ipv6_server(const char *ipv6_address, int port) { int server_fd; struct sockaddr_in6 server_addr; server_fd = socket(AF_INET6, SOCK_STREAM, 0); if (server_fd == -1) { perror("socket() failed"); return -1; } memset(&server_addr, 0, sizeof(server_addr)); server_addr.sin6_family = AF_INET6; server_addr.sin6_port = htons(port); if (inet_pton(AF_INET6, ipv6_address, &server_addr.sin6_addr) <= 0) { perror("inet_pton() failed"); close(server_fd); return -1; } if (bind(server_fd, (struct sockaddr *)&server_addr, sizeof(server_addr)) == -1) { perror("bind() failed"); close(server_fd); return -1; } if (listen(server_fd, 5) == -1) { perror("listen() failed"); close(server_fd); return -1; } printf("Server is listening on [%s]:%d\n", ipv6_address, port); return server_fd; } int dx_accept_client_connection(int server_fd) { int client_fd; struct sockaddr_in6 client_addr; socklen_t client_addr_len = sizeof(client_addr); client_fd = accept(server_fd, (struct sockaddr *)&client_addr, &client_addr_len); if (client_fd == -1) { perror("accept() failed"); return -1; } char client_ip[INET6_ADDRSTRLEN]; inet_ntop(AF_INET6, &client_addr.sin6_addr, client_ip, sizeof(client_ip)); printf("Client connected: [%s]\n", client_ip); return client_fd; } int dx_connect_to_ipv6_server(const char *ipv6_address, int port) { int client_fd; struct sockaddr_in6 server_addr; client_fd = socket(AF_INET6, SOCK_STREAM, 0); if (client_fd == -1) { perror("socket() failed"); return -1; } memset(&server_addr, 0, sizeof(server_addr)); server_addr.sin6_family = AF_INET6; server_addr.sin6_port = htons(port); if (inet_pton(AF_INET6, ipv6_address, &server_addr.sin6_addr) <= 0) { perror("inet_pton() failed"); close(client_fd); return -1; } if (connect(client_fd, (struct sockaddr *)&server_addr, sizeof(server_addr)) == -1) { perror("connect() failed"); close(client_fd); return -1; } printf("Connected to server [%s]:%d\n", ipv6_address, port); close(client_fd); return 0; } @implementation SocketTest + (void)startSever:(NSString *)addr port:(int)port { [[NSOperationQueue new] addOperationWithBlock:^{ int server_fd = dx_create_ipv6_server(addr.UTF8String, port); if (server_fd == -1) { return; } int client_fd = dx_accept_client_connection(server_fd); if (client_fd == -1) { close(server_fd); return; } close(client_fd); close(server_fd); }]; } + (void)clientConnect:(NSString *)addr port:(int)port{ [[NSOperationQueue new] addOperationWithBlock:^{ dx_connect_to_ipv6_server(addr.UTF8String, port); }]; } @end PacketTunnelProvider code: override func startTunnel(options: [String : NSObject]?, completionHandler: @escaping (Error?) -> Void) { let settings = NEPacketTunnelNetworkSettings(tunnelRemoteAddress: "fd84:306d:fc4e::1") let ipv6 = NEIPv6Settings(addresses: ["fd84:306d:fc4e::1"], networkPrefixLengths: 64) settings.ipv6Settings = ipv6 setTunnelNetworkSettings(settings) { error in if error == nil { self.readPackets() } completionHandler(error) } } private func readPackets() { // do nothing packetFlow.readPackets { [self] packets, protocols in self.packetFlow.writePackets(packets, withProtocols: protocols) self.readPackets() } } At main target, in viewcontroller's viewDidAppear, after starting the VPN, executed following code: [SocketTest startSever:@"fd84:306d:fc4e::1" port:12345]; sleep(3); [SocketTest clientConnect:@"fd84:306d:fc4e::1" port:12345]; The startSever is executed correctly, but when executing: connect(client_fd, (struct sockaddr *)&server_addr, sizeof(server_addr)) in clientConnect, the code is blocked until it times out and returns -1. **Even if I use GCDAsyncSocket or BlueSocket, I get the same error. The strange thing is that if I use the ipv4 address in PacketTunnelProvider, and change the above code to the ipv4 version and connect to ipv4 address, or use GCDAsyncSocket to perform the corresponding operation, it can be executed correctly. ** I tried to search Google for problems with ios-related ipv6 addresses, but I still couldn't find a solution. Is this a bug in the ios system or is there something wrong with my code? I hope to get your help! Stackoverflow url: iOS Socket cannot connect ipv6 address when use PacketTunnelProvider
13
0
219
2w
RunLoop behaviour change with performBlock?
I have a dedicated render thread with a run loop that has a CADisplayLink added to it (that's the only input source attached). The render thread has this loop in it: while (_continueRunLoop) { [runLoop runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]; } I have some code to stop the render thread that sets _continueRunLoop to false in a block, and then does a pthread_join on the render thread: [_renderThreadRunLoop performBlock:^{ self->_continueRunLoop = NO; }]; pthread_join(_renderThread, NULL); I have noticed recently (iOS 18?) that if the Display Link is paused or invalidated before trying to stop the loop then the pthread_join blocks forever and the render thread is still sitting in the runMode:beforeDate: method. If the display link is still active then it does exit the loop, but only after one more turn of the display link callback. The most likely explanation I can think of is there has been a behaviour change to performBlock - I believe this used to "consume" a turn of the run loop, and exit the runMode:beforeDate call but now it happens without leaving that function. I can't find specific mention in the docs of the expected behaviour for performBlock - just that other RunLoop input sources cause the run method to exit, and timer sources do not. Is it possible that the behaviour has changed here?
4
0
104
1w
How to get access of Admin Submission/Completion queues for NVMe devices from any driver or user space application to submit Admin command ?
Few user space applications are available in market for example xnvme, but does not have any interaction with Admin Submission/Completion queues. Also IOCTLs are not very prominent . Is there any ways to get access to the native NVMe Mac driver source code? Thanks, hopefully we will get some positive response here.
3
0
761
Jan ’24