Posts

Post not yet marked as solved
1 Replies
If you omit the modifiers argument, if defaults to .command, so if you try cmd + space, your keyboard shortcut will probably work. public func keyboardShortcut(_ key: KeyEquivalent, modifiers: EventModifiers = .command) -> some View Try .keyboardShortcut(.space, modifiers: []) and space on its own should work.
Post marked as solved
2 Replies
I don't think this is possible yet in a pure SwiftUI way. I raised a Technical Support Incident for this as I too needed to know how and the solution I received from Apple is below: if let windowScene = UIApplication.shared.connectedScenes.first(where: { $0.activationState == .foregroundActive }) as? UIWindowScene { SKStoreReviewController.requestReview(in: windowScene) } I was hoping the active scene would be available as an @Environment value, but alas no. My app uses the SwiftUI lifecycle and so I prefer not to fall back to UIApplication like this.
Post marked as solved
13 Replies
Did you get this to work? I have a similar need, that is, to offer iCloud storage and sync as a premium feature. I have CloudKit sync working but how do I switch it off? I want to disable CloudKit sync and only enable it when a customer pays for the premium version. I've tried setting the container's cloudKitContainerOptions property to nil but CloudKit sync still happens.Here's my Core Data stack:private lazy var persistentContainer: NSPersistentContainer = { let container = NSPersistentCloudKitContainer(name: modelName) let localDescription = NSPersistentStoreDescription(url: configurationsURL.appendingPathComponent("local.sqlite", isDirectory: false)) localDescription.configuration = "Local" let cloudDescription = NSPersistentStoreDescription(url: configurationsURL.appendingPathComponent("cloud.sqlite", isDirectory: false)) cloudDescription.configuration = "Cloud" cloudDescription.cloudKitContainerOptions = NSPersistentCloudKitContainerOptions(containerIdentifier: cloudKitContainerIdentifier) cloudDescription.setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey) cloudDescription.setOption(true as NSNumber, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey) container.persistentStoreDescriptions = [localDescription, cloudDescription] container.loadPersistentStores { (storeDescription, error) in if let error = error as NSError? { fatalError("###\(#function): Failed to load persistent stores:\(error)") } } container.viewContext.name = "main" container.viewContext.transactionAuthor = appTransactionAuthorName container.viewContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy container.viewContext.automaticallyMergesChangesFromParent = true do { try container.viewContext.setQueryGenerationFrom(.current) } catch { fatalError("###\(#function): Failed to pin viewContext to the current generation:\(error)") } NotificationCenter.default.addObserver(self, selector: #selector(type(of: self).storeRemoteChange(_:)), name: .NSPersistentStoreRemoteChange, object: nil) // do {// //try container.initializeCloudKitSchema(options: [.dryRun, .printSchema])// try container.initializeCloudKitSchema()// } catch {// let nserror = error as NSError// print("Could not initialize CloudKit schema: \(error.localizedDescription)")// print(nserror.code)// print(nserror.domain)// } return container }()Ands here's a function where I'm trying to toggle the CloudKit sync:func enableiCloud(_ isEnabled: Bool) { let cloudDescription = persistentContainer.persistentStoreDescriptions.first() { $0.configuration == "Cloud" } guard cloudDescription != nil else { return } if isEnabled { cloudDescription!.cloudKitContainerOptions = NSPersistentCloudKitContainerOptions(containerIdentifier: cloudKitContainerIdentifier) cloudDescription!.setOption(true as NSNumber, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey) } else { cloudDescription!.cloudKitContainerOptions = nil cloudDescription!.setOption(false as NSNumber, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey) } }