Post

Replies

Boosts

Views

Activity

WKNavigationDelegate never called (Obj-C, macOS)
I'm adding a WKWebView to my (Mac) app, and it works fine except that the navigationDelegate is never called. Even stranger, if that delegate implements decidePolicyForNavigationAction, that method is never called either, but as a side effect the view now won't load any pages! In detail: I've created a class implementing WKNavigationDelegate, I've implemented some of the methods, and assigned an instance to the view's navigationDelegate property. Easy stuff. I've done this in the past using the old-school WebView class. I've triple-checked my work. As an experiment, I added a -respondsToSelector: method to my delegate class and made it log the selector. I see it being called several dozen times, with the selectors for all of the delegate methods and many other private(?) methods; so I know WebKit sees my object. It just never calls it at all. My hunch so far is that this is an OS bug, that Apple no longer bothers to test WebKit APIs in Objective-C. I'd hate for that to be true. (I realize Obj-C is basically deprecated nowadays. I'm using it because my non-UI code is all in C++, and it's vastly easier to integrate with C++ in Obj-C. To use Swift I'm going to have to wrap my API in C functions, yuck.)
4
0
2.3k
May ’22
Shared-memory pthread condition variable not working
I’m trying to implement a simple cross-process notify/observe system, using a pthread mutex and condition variable in shared (mapped) memory. It seems to be working fine (on macOS 11.6) if one process calls pthread_cond_wait and then another calls pthread_cond_broadcast — the waiting process indeed wakes up. However, if two processes try to observe at the same time, the second one's call to pthread_cond_wait fails with EINVAL. I’m wondering if I’m just doing something wrong in my setup, or if this sort of usage isn’t supported. Basically I create and mmap a file, initialize a pthread mutex and condition in the mapped memory using the setpshared attributes, then lock the mutex and notify or wait on the condition. Actual source code here: Here’s the code that does the pthreads stuff Here’s the outer code that opens and mmaps the file I’m aware that there are a few dozen 🙄 Apple IPC APIs that are probably preferred over these POSIX ones. I’ve used some in the past. I’m doing it this way because: (a) this is in a cross-platform project and it would be nice to share code between Unix platforms, at least Darwin and Linux; (b) the thing I’m notifying/observing about is a database file, so tying the notifications to a side file next to the database provides ideal scoping; (c) it’s similar in principle to the usage of shared memory for locking in SQLite and LMDB. (The difference is, I’m doing notification not locking.) Any advice? —Jens
1
1
1.1k
Oct ’21
Reducing overhead of CKRecord.encodeSystemFields
TL;DR: I'm syncing a local database to CloudKit and I'd like to store only the CKRecord's recordChangeTag locally, because the archived system fields are quite large. Is there any way to create a CKRecord with a given recordChangeTag? I'm working on syncing an on-device database to CloudKit. As part of this I need to remember the CloudKit state of every database record, so I when that record changes I can create a CKRecord for it and push it to the server. The supported way to do this is to call CKRecord.encodeSystemFields on the resulting record after the push, and save that archived data alongside the local record so it can be reconstituted into a CKRecord next time I need to push that database row. The problem is that this archived data is pretty heavyweight, generally about 1600 bytes. That's not a lot for one record, but for 60,000 records it's 100MB of extra data to store (and read and write.) As far as I can tell, the only really crucial part of a CKRecord to push (besides the ID and type, which I already know) is the recordChangeTag — this is what the server uses as the MVCC token to reject conflicting updates. And this tag is tiny: it appears to be a hex-encoded generation count, so it's usually 1 or 2 bytes. I'd like to store just this tag. But I can't use it to reconstitute a CKRecord, because that property isn't settable. Is there any workaround?
1
0
722
Aug ’20