Date   

Auto layout help

John Brownie
 

I have my web view displaying correctly, but I've run into a problem in getting the auto layout constraints working correctly. Basically, I build the appropriate web view as a subview of a custom view, which is in turn embedded in a view within a window. The problem is that, if I set constraints on the custom view, the window stops being resizable, and I can't work out why.

Here's the code for the constraints:

let variableBindings = ["webView": webView]
let constraints1 = NSLayoutConstraint.constraints(withVisualFormat: "H:|-0-[webView]-0-|", options: [], metrics: nil, views: variableBindings)
let constraints2 = NSLayoutConstraint.constraints(withVisualFormat: "V:|-0-[webView]-0-|", options: [], metrics: nil, views: variableBindings)
webContentView.addConstraints(constraints1)
webContentView.addConstraints(constraints2)

I have very similar code for the actual web view within its containing view. If I have only those and not the outer constraints, the window is resizable, but the container for the web view doesn't resize.

I must be doing something wrong, obviously, but I have run out of ideas on how to find my problem. Needless to say, this is the first time I've had to do auto layout in code.

Thanks for any insights,
John
--
John Brownie
Mussau-Emira language, New Ireland Province, Papua New Guinea
Kouvola, Finland


Re: How to present a web view while supporting 10.9?

John Brownie
 

Thanks for all the tips. I have it all worked out now.

John

Jens Alfke wrote on 7/2/20 21:39:

You'll need two code paths, one that instantiates and runs a WebView, the other that instantiates and runs a WKWebView. Their APIs and functionality are not identical, so it's not just a question of "how do I get IB to instantiate the right class". Your controller code needs to be different.

I would create my own abstract view and controller class for this (MyWebView and MyWebViewController?), then have concrete subclasses of each for the old and new WebViews. Each view class instantiates the appropriate system view and makes it a subview of itself.
--
John Brownie
Mussau-Emira language, New Ireland Province, Papua New Guinea
Kouvola, Finland


Re: How to present a web view while supporting 10.9?

 

You'll need two code paths, one that instantiates and runs a WebView, the other that instantiates and runs a WKWebView. Their APIs and functionality are not identical, so it's not just a question of "how do I get IB to instantiate the right class". Your controller code needs to be different.

I would create my own abstract view and controller class for this (MyWebView and MyWebViewController?), then have concrete subclasses of each for the old and new WebViews. Each view class instantiates the appropriate system view and makes it a subview of itself.

—Jens


Re: How to present a web view while supporting 10.9?

Sandor Szatmari
 

Yes I could have been more specific, everything worked, all be it with warnings, with both classes of web views being instantiated in code.  

Sandor

On Feb 7, 2020, at 10:13, John Brownie <john_brownie@...> wrote:

I should note that, once I put the WKWebView into the window, there is an error that I hadn't noticed before:
error: Class Unavailable: WKWebView before macOS 10.12 (NSCoding support was broken in previous versions)
So I would have to drop support for 10.9-10.11 to use WKWebView, so I really need to work out how to do this.

Is building the window in code the solution?

John


Re: ***UNCHECKED*** Re: [cocoa-dev] How to present a web view while supporting 10.9?

Owen Hartnett
 

Yes.  Prior to 10.12, WKWebView was not available in Interface Builder and could only be instantiated in code.

-Owen

On Feb 7, 2020, at 10:13 AM, John Brownie <john_brownie@...> wrote:

I should note that, once I put the WKWebView into the window, there is an error that I hadn't noticed before:
error: Class Unavailable: WKWebView before macOS 10.12 (NSCoding support was broken in previous versions)
So I would have to drop support for 10.9-10.11 to use WKWebView, so I really need to work out how to do this.

Is building the window in code the solution?

John


Re: How to present a web view while supporting 10.9?

John Brownie
 

I should note that, once I put the WKWebView into the window, there is an error that I hadn't noticed before:
error: Class Unavailable: WKWebView before macOS 10.12 (NSCoding support was broken in previous versions)
So I would have to drop support for 10.9-10.11 to use WKWebView, so I really need to work out how to do this.

Is building the window in code the solution?

John


Re: How to present a web view while supporting 10.9?

John Brownie
 

Thanks for the reply.

Sandor Szatmari wrote on 6/2/20 20:51:
What SDK are you building against?
I assuming deployment target of 10.9 and not earlier…
I'm still on 10.14.6, Xcode 11.0, current SDK, which I assume is 10.14 (I can't see an option to choose anything but a platform in the SDK pop-up).
What is the exact problem your having? Is it just warnings, or are there compile/link/runtime errors…
I create a window in IB, and add a WKWebView to fill the content view. I then create an outlet to that, and Xcode wants me to mark the whole class (in Swift) as being available in 10.10 or later, and that's an error, not a warning. So there is a problem with what I do if I'm running on 10.9. Maybe I should just do it in Objective-C instead?

I have done this before with API available only on some platforms, but it's the first time I've run across it in a view built with IB. It's probably something quite simple, but I haven't been able to find an answer.
I just set the deployment target of an app with a WKWebView to 10.9 and build SDK 10.14. I got warnings of WKWebview et. all… not being available on 10.9 but it compiled and ran fine on Mojave. I’m assuming the availability conditionals would allow selection of WebView code if I ran it on some earlier release.
Not having the luxury of more than my own computer to test on, I can't tell what would happen if I did that and ran on 10.9. I'm still in the design/coding phase of this particular item.
I added a reference to a plain WebView and it did not complain about that with the deployment target set to 10.9.
With all the dire warnings about not using WebView, I'd much rather aim for WKWebView if possible. And this is only for a maintenance release, so I don't want to change the deployment target to 10.10 just for this.

John
--
John Brownie
Mussau-Emira language, New Ireland Province, Papua New Guinea
Kouvola, Finland


Re: How to present a web view while supporting 10.9?

Sandor Szatmari
 

What SDK are you building against?
I assuming deployment target of 10.9 and not earlier…

What is the exact problem your having? Is it just warnings, or are there compile/link/runtime errors…

I just set the deployment target of an app with a WKWebView to 10.9 and build SDK 10.14. I got warnings of WKWebview et. all… not being available on 10.9 but it compiled and ran fine on Mojave. I’m assuming the availability conditionals would allow selection of WebView code if I ran it on some earlier release.

I added a reference to a plain WebView and it did not complain about that with the deployment target set to 10.9.

Sandor


On Feb 6, 2020, at 08:07, John Brownie <john_brownie@sil.org> wrote:

My app currently supports 10.9, and I want to add a feature that displays an HTML document stored locally (in the bundle). The obvious way is to have a window which contains a web view. However, WKWebView is only available in 10.10, and WebView is deprecated.

If it were a matter of calling a method, I could wrap it with availability calls, but it's a definition of the class of an element in a window controller class. Presumably there is a way to handle this, but I haven't discovered it.

What I'm looking for is something like

if #available(macOS 10.10, *) {
var webView: WKWebView
}
else {
var webView: WebView
}

...but that is for running code, not declarations.

Is there a way to do this through IB? Or is my alternative to build the window in code, using whatever is available based on the runtime platform?

John
--
John Brownie
Mussau-Emira language, New Ireland Province, Papua New Guinea
Kouvola, Finland



Is it necessary to suspend/resume a dispatch queue/source on sleep/wake notifications?

Matt DeFoor
 

Does anyone know if it is necessary to dispatch_suspend/resume a queue or source when sleep/wake notifications triggered in a macOS app?

I've read the docs and done some searching but couldn't find anything definitive other than the concurrency programming guide states that all timer dispatch sources are suspended when a computer goes to sleep. When the computer wakes up, they are woken up as well.

Thanks (sorry for the cross-post to Cocoa-Dev),
Matt


How to present a web view while supporting 10.9?

John Brownie
 

My app currently supports 10.9, and I want to add a feature that displays an HTML document stored locally (in the bundle). The obvious way is to have a window which contains a web view. However, WKWebView is only available in 10.10, and WebView is deprecated.

If it were a matter of calling a method, I could wrap it with availability calls, but it's a definition of the class of an element in a window controller class. Presumably there is a way to handle this, but I haven't discovered it.

What I'm looking for is something like

if #available(macOS 10.10, *) {
    var webView: WKWebView
}
else {
    var webView: WebView
}

...but that is for running code, not declarations.

Is there a way to do this through IB? Or is my alternative to build the window in code, using whatever is available based on the runtime platform?

John
--
John Brownie
Mussau-Emira language, New Ireland Province, Papua New Guinea
Kouvola, Finland


Re: Setting accessibility text for a table cell view

John Brownie
 

I found my stupid error, that I should be calling -setAccessibilityValueDescription:, rather than -setAccessibilityValue: or -setAccessibilityTitle:. A case of reading what I initially found more carefully!

John


Re: Setting accessibility text for a table cell view

John Brownie
 

Nobody?

I've been playing around with the Accessibility Inspector, and it seems that there are both Title and Value which get read out. I don't seem to be able to set the value, though, as it is being derived down in the NSTextFieldCell, and it trumps whatever I try to set at the NSTextField level.

Another issue is when the text field has an empty string. I would like to have something read out by VO, but setting the title doesn't work.

All of this is being done in -tableView:viewForTableColumn:row:, but perhaps there's a better place to do it?

Ideally, I'd like to support back to 10.9, but I'm willing to use later if necessary.

John


XCTests and test start and stop events.

Alex Zavatone
 

Last week I got the XCTest details sorted out and ended up with an observer class that ends up quite like the iOS AppDelegate does for app start and stop events but for test bundle events.

The big trick is figuring out how to use NSPrincipalClass in the info.plist.

What I use this for is to trigger loggers when test bundle events happen and through an external (hacky) script automatically run a heap dump and generate a leaks memgraph automatically when out iOS tests run.

If this would be of use to anyone, I can send it your way or put it up on GitHub.

Cheers,
Alex Zavatone


Setting accessibility text for a table cell view

John Brownie
 

I'm new at accessibility, and have recently been supporting a blind user. One of the tables in my conveys information in shorthand by using colours and styles, which don't come across with VoiceOver. I'd like to be able to have VO read an alternate text when reading the cell. It's a basic view-based table, using NSTableCellView.

I searched and found an old solution involving subclassing NSTableCellView and overriding accessibilityAttributeValue, but that's deprecated.
https://stackoverflow.com/questions/16193012/nstextfield-accessibility-how-to-provide-alternate-text-for-voiceover

If I set the accessibility title, I get the contents of the cell and my alternate text read, but I only want the alternate text to be read out. Do I need to subclass, and if so, what methods do I need to override? Or what other calls should I make to get only what I want read by VO?

Thanks for any pointers!

John
--
John Brownie
Mussau-Emira language, New Ireland Province, Papua New Guinea
Kouvola, Finland


Re: Weird Error Message

Bernie Maier
 

On Sat, 18 Jan 2020, at 9:26 PM, Dave wrote:
Hi All,

I’m getting this message in the XCode log whenever I run my App:

2020-01-18 11:19:15.773124+0100 SudokuSolverForMac[27373:7517021] flock failed to lock maps file: errno = 35

Should I be worried?


Research led to the determination that the messages are posted when you have more than one instance of a program running at the same time which might also have the same file open.

Is it possible that you have two instances of your app running and they both are somehow required write access to a globally shared file?

Unfortunately, I don’t know what I maps file is in this context, and that term on its own is too general to search for.

Cheers,
Bernie


Weird Error Message

Dave
 

Hi All,

I’m getting this message in the XCode log whenever I run my App:

2020-01-18 11:19:15.773124+0100 SudokuSolverForMac[27373:7517021] flock failed to lock maps file: errno = 35

Should I be worried?

All the Best
Dave


NSPrincipalClass in info.plist on iOS

Alex Zavatone
 

Has anyone successfully gotten this to work to indicate which class to load on target startup? I am using an XCTest target and Apple’s docs for XCTestObservationCenter state that the info.plist NSPrincipalClass key is the preferred method to start a class to add the observer.

Thanks in advance,
Alex Zavatone


Re: Properties being set to nil?

Alex Zavatone
 

If the address is different it is another instance.


On Jan 16, 2020, at 11:20 AM, Dave <dave@...> wrote:

Hi,

This is the only place the View Controller is instantiated. One thing I’ve notice is that if I set a breakpoint in ViewDidLoad and print self:

< LTWMacGameViewController: 0x600003500840>

and then again in setGameControlDelegate

<LTWMacGameViewController: 0x6000035082c0>

The addresses are different, so it looks like the View Controller returned by instantiateControllerWithIdentifier is different to the one actually instantiated?

Cheers
Dave


On 16 Jan 2020, at 18:00, Jon Gotow <gotow@...> wrote:

Any chance you're reloading your view controller (when starting a new game or whatever) and not subsequently setting the delegates again?

- Jon


On Jan 16, 2020, at 9:55 AM, Dave <dave@...> wrote:

Hi All,

I have a View Controller that is Instantiated in code from a storyboard file:

myGameViewController = [myStoryboard instantiateControllerWithIdentifier:kLTWGameMainViewControllerID];
if (myGameViewController == nil)
{
return;
}

I then set some delegates:

[myGameViewController setGameControlDelegate:[self getGameControlDelegate]];
[myGameViewController setGameCommandDelegate:[self getGameCommandDelegate]];

These methods just store the delegate in Strong properties, I’ve checked and they are set ok.

However, I put a break point in viewDidLoad: and look at the properties again they have been set to nil!

I’ve checked and the properties in question are only set once in the appropriate setDelagateMethod.

Is there some magic going on? Is it legal to do this?

Thanks in advance for any help?

Dave












Re: Properties being set to nil?

Dave
 

Hi Jon,

Thanks a lot!

I was just about coming to the same conclusion and was trying to figure out how to get the ViewController from the Window and then your message arrived.

That fixed it! All working well now!

Thanks again
Dave

On 16 Jan 2020, at 20:27, Jon Gotow <gotow@stclairsoft.com> wrote:

Oh - there you go. Assuming that myGameWindowController is the parent window controller that manages myGameViewController, it will create an instance of your LTWMacGameViewController class when it loads. Calling [myStoryboard instantiateControllerWithIdentifier:kLTWGameMainViewControllerID] afterwards will create another instance of LTWMacGameViewController that's just floating in memory, not referenced by the window controller.

What you want to do is get the instance of LTWMacGameViewController that's managed by the window controller. Do this instead:

myGameViewController = myGameWindowController.contentViewController;

That'll fix it.

- Jon


On Jan 16, 2020, at 11:38 AM, Dave <dave@looktowindward.com> wrote:

//**
//** Instantiate the Game Window Controller
//**
myStoryboard = [NSStoryboard storyboardWithName:kLTWGameStoryboardName bundle:nil];
myGameWindowController = [myStoryboard instantiateControllerWithIdentifier:kLTWGameMainWindowControllerID];
if (myGameWindowController == nil)
{
return;
}

//**
//** Instantiate the Game View Controller
//**
myGameViewController = [myStoryboard instantiateControllerWithIdentifier:kLTWGameMainViewControllerID];
if (myGameViewController == nil)
{
return;
}




Re: Properties being set to nil?

Jon Gotow
 

Oh - there you go. Assuming that myGameWindowController is the parent window controller that manages myGameViewController, it will create an instance of your LTWMacGameViewController class when it loads. Calling [myStoryboard instantiateControllerWithIdentifier:kLTWGameMainViewControllerID] afterwards will create another instance of LTWMacGameViewController that's just floating in memory, not referenced by the window controller.

What you want to do is get the instance of LTWMacGameViewController that's managed by the window controller. Do this instead:

myGameViewController = myGameWindowController.contentViewController;

That'll fix it.

- Jon

On Jan 16, 2020, at 11:38 AM, Dave <dave@looktowindward.com> wrote:

//**
//** Instantiate the Game Window Controller
//**
myStoryboard = [NSStoryboard storyboardWithName:kLTWGameStoryboardName bundle:nil];
myGameWindowController = [myStoryboard instantiateControllerWithIdentifier:kLTWGameMainWindowControllerID];
if (myGameWindowController == nil)
{
return;
}

//**
//** Instantiate the Game View Controller
//**
myGameViewController = [myStoryboard instantiateControllerWithIdentifier:kLTWGameMainViewControllerID];
if (myGameViewController == nil)
{
return;
}

241 - 260 of 1426