Hi,
does someone knows about the bug, that the NSPersistentCloudKitContainer doesn't return CKShares at the first time? Is this an intended behavior?
My current fix:
let container: NSPersistentCloudKitContainer = ....
// Fix begin
let managedObject = .... // Object which is in a share
let record = container.record(for: managedObject.objectID)
// Fix end
let shares = (try? container.fetchShares(in: nil)) ?? []
If I execute exactly the same code without the fix that I fetch the record first, then it returns 0 shares. With the fix it is currently 9 shares (the actual count of the shares).
Another fix:
let container: NSPersistentCloudKitContainer = ....
// Fix begin
let _ = try? container.fetchShares(in: nil)
Thread.sleep(forTimeInterval: 0.1)
// Fix end
let shares = (try? container.fetchShares(in: nil)) ?? []
For that fix it also returns at the second time the expected count of shares. But without the delay it returns also at the second time zero shares.
Anyone had the same problem and if so, how do you solve it correctly?
Thanks!
Post
Replies
Boosts
Views
Activity
Hello,
Prior to iOS 17, it was possible to request user discoverability by calling ‚requestApplicationPermission‘. But now it is deprecated. How is the intended way to do this now? How this is for example handled in the Music App? I think this should be a similar approach.
Currently the only option for me seems to save the Email-Address (and maybe phone number) in the CloudKit public database, that other user can discover by this. But that the problem exists, that we need to fetch for changes at phone numbers and mail addresses that are linked to the iCloud account (because user might change anything). Is there a more elegant solution, than just checking the current email addresses and phone numbers at each start of the application (if that is even possible)?
For example the Music App has that Switch "Find my by Apple-ID" but I don't know how this is handled in the background.
Thanks!
Hi,
I have created a custom UIContentConfiguration + UIContentView for a TableView and using the custom Configuration and the default Configuration from UIListContentConfiguration in a same TableView (Style insetGrouped). But the separators from the custom configuration are different than that from the default configuration. And I didn't see an option to modify this through the custom configuration. Do anybody know how this is done with UIListContentConfiguration? For me currently the only option seems to be using "cell.separatorInset", but for the UIListContentConfiguration I don't need this.
In the image below you see the problem. First, third and fifth cell is default configuration (UIListContentConfiguration.valueCell()). Second and fourth is the custom configuration. And under the custom configuration cells the separator is beginning at zero. This can be fixed with: cell.separatorInset.left = 20.
This one is an example without image, but if I add an image for the default configuration, the text is much more behind and the fix with cell.separatorInset.left = 20 is not working in this case.
For default configuration:
let cell = tableView.dequeueReusableCell(withIdentifier: "default", for: indexPath)
var config = UIListContentConfiguration.valueCell()
config.text = "Test"
config.secondaryText = "Test"
cell.contentConfiguration = config
return cell
For custom configuration:
Configuration + ContentView:
struct SwitchConfiguration: UIContentConfiguration {
var text: String?
var value: Bool
var delegate: SwitchDelegate?
func makeContentView() -> UIView & UIContentView {
return SwitchContentView(configuration: self)
}
func updated(for state: UIConfigurationState) -> SwitchConfiguration {
return self
}
}
class SwitchContentView: UIView, UIContentView {
var configuration: UIContentConfiguration {
didSet {
self.configure()
}
}
private let textLabel: UILabel = UILabel()
private let `switch`: UISwitch = UISwitch()
init(configuration: UIContentConfiguration) {
self.configuration = configuration
super.init(frame: .zero)
self.switch.addTarget(self, action: #selector(self.switchValueDidChange(_:)), for: .valueChanged)
self.addSubview(self.textLabel)
self.addSubview(self.switch)
self.directionalLayoutMargins = .init(top: 8, leading: 20, bottom: 8, trailing: 8)
self.textLabel.translatesAutoresizingMaskIntoConstraints = false
self.textLabel.leadingAnchor.constraint(equalTo: self.layoutMarginsGuide.leadingAnchor).isActive = true
self.textLabel.centerYAnchor.constraint(equalTo: self.layoutMarginsGuide.centerYAnchor).isActive = true
self.switch.translatesAutoresizingMaskIntoConstraints = false
self.switch.trailingAnchor.constraint(equalTo: self.layoutMarginsGuide.trailingAnchor, constant: -16).isActive = true
self.switch.centerYAnchor.constraint(equalTo: self.layoutMarginsGuide.centerYAnchor).isActive = true
self.switch.topAnchor.constraint(equalTo: self.layoutMarginsGuide.topAnchor).isActive = true
self.switch.bottomAnchor.constraint(equalTo: self.layoutMarginsGuide.bottomAnchor).isActive = true
self.configure()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func configure() {
guard let config = self.configuration as? SwitchConfiguration else {
return
}
self.textLabel.text = config.text
self.switch.isOn = config.value
}
@IBAction
func switchValueDidChange(_ switch: UISwitch) {
guard let config = self.configuration as? SwitchConfiguration else {
return
}
config.delegate?.switchValueDidChange(`switch`.isOn)
}
}
Cell:
let cell = tableView.dequeueReusableCell(withIdentifier: "custom", for: indexPath)
var config = SwitchConfiguration()
config.text = "Test"
config.value = true
cell.contentConfiguration = config
//cell.separatorInset.left = 20
return cell
When using the Date Picker Style "compact" from iOS 14 a popup with the calendar is opened, when the user taps on the date. It is possible to trigger this popup without any user interaction?
Hey,im trying to get the NWConnection on watchOS 6 working. The NWConnection is working completly fine in combination with the iPhone, but if I disconnect the iPhone (Airplane Mode, WiFi and Bluetooth Off) the connection is not working, but the apple watch is connected with the wifi.Normally the Apple Watch (mine a Series 4) can connect to a server without an iPhone, too?Here the minimal example code (Created Watch-App iOS-Project with XCode 11.5 - InterfaceBuilder). The only thing I changed is I added an Label to the Watch-Interface and the following InterfaceController.swift in WatchKit Extension:(Just for Info. The Server will just return "OK MPD 0.19.0\n" at connect)import WatchKit
import Foundation
import Network
class InterfaceController: WKInterfaceController {
@IBOutlet weak var label: WKInterfaceLabel!
private var connection : NWConnection?
private var dispatchQueue = DispatchQueue(label: "connection")
override func awake(withContext context: Any?) {
super.awake(withContext: context)
}
override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
self.label.setText("Version")
let endpoint = NWEndpoint.hostPort(host: .name("192.168.178.10", nil), port: 6600)
let parameters = NWParameters.tcp
self.connection = NWConnection(to: endpoint, using: parameters)
self.connection?.stateUpdateHandler = .some({ (state) in
print("Received State=\(state)")
switch state {
case .ready:
self.label.setText("READY")
self.connection?.receive(minimumIncompleteLength: 1, maximumLength: 1024, completion: { (data, contentContext, isComplete, error) in
if let data = data, data.count > 0, let string = String(data: data, encoding: .utf8) {
let arr = string.components(separatedBy: "\n")
let VERSION_PREFIX = "OK MPD"
for item in arr {
if item.hasPrefix(VERSION_PREFIX) {
// Received Version
let version = item[item.index(item.startIndex, offsetBy: VERSION_PREFIX.count)...]
var text = String(version)
if let path = self.connection?.currentPath {
text += " - Uses Others=\(path.usesInterfaceType(.other)) Uses Wifi=\(path.usesInterfaceType(.wifi))"
}
self.label.setText(text)
break
}
}
}
})
break
case .waiting(let error):
self.label.setText("Waiting Error=\(error)")
break
case .failed(let error):
self.label.setText("Failed Error=\(error)")
default:
break
}
})
self.connection?.start(queue: self.dispatchQueue)
}
override func didDeactivate() {
// This method is called when watch view controller is no longer visible
self.connection?.cancel()
super.didDeactivate()
}
}It is because the Watch could not connect to a server without the iPhone or am I missing something?Thanks and RegardsAdrian