Re: Objective-C: What is the current preferred method of declaring constants without a .pch?
On Oct 19, 2017, at 12:11 PM, Alex Zavatone <zav@...> wrote:Wait, what? I never got the memo on this. Is it good practice to create one constants.h/m? Or is that just another way of masking a global (which is bad)?I put constants in the headers for the classes/APIs they are used with. If you look at Cocoa headers you can see Apple does the same thing. Also, this is a separate issue from whether to use a prefix or precompiled header. Ideally your code should be buildable without a prefix header, i.e. every source file should #import the headers it depends on. The precompiled prefix header is just to speed up builds. —Jens |
|
Re: Objective-C: What is the current preferred method of declaring constants without a .pch?
Bernie Maier
Alex Zavatone:
I understand that a .pch is now a “bad idea”. OK. What do we doPre-compiled headers are now considered to be a bad idea, yes, but although traditionally the *prefix* header was usually pre-compiled it doesn't have to be. So what I use in some of my project is a prefix header that simply isn't pre-compiled. That said, I use it *extremely* sparingly, kind of like a more SCM-friendly place to define constants like conditional compilation flags that need to consistent across an entire build. These are often supplied as -D arguments to the compiler, and thus often live in relative obscurity amongst other project settings. Like others, I would normally attach more specific constants to whatever they are most related to. |
|
Re: Objective-C: What is the current preferred method of declaring constants without a .pch?
Alex Zavatone
Thanks Steve. That’s one option I’ve been considering. It’s a balance between knowing where to look for everything and properly scoping some constant to the one place where I use it. If there’s one thing that wastes my time, it’s hunting through my project for a constant, but if it only needs to be in one place, then I probably should learn to expect looking for it in the class that uses it.
toggle quoted message
Show quoted text
FYI, if anyone needs a little more explanation of how to handle this with modules, I just found this relatively recent link that may help us stay current. It mentions how to use the umbrella header within modules if you’re using them. Also Ash Furrow has some good input. Thanks for your time everyone. - Alex Zavatone
|
|
Re: Objective-C: What is the current preferred method of declaring constants without a .pch?
Steve Christensen <punster@...>
I use constants a lot, but I put their declarations and definitions into the "owner" class files. For example if one object sources notifications and others consume them.
toggle quoted message
Show quoted text
Foo.h extern NSString* const __nonnull FooNotification; Foo.m NSString* const FooNotification = @"FooNotification"; With Obj-C I have rarely ended up with true globals since I can create singletons as "global" instances of particular classes. I have created .h files containing some #defines that are used to conditionally compile certain features that may not be quite ready for primetime and so it could get pulled before an app ships. Steve On Oct 19, 2017, at 12:11 PM, Alex Zavatone <zav@...> wrote: |
|
Objective-C: What is the current preferred method of declaring constants without a .pch?
Alex Zavatone
I’ve read the Apple docs and looked around and can’t find definitive sources on what the preferred method is and how to do it.
Do we use modules? If so, how? I understand that a .pch is now a “bad idea”. OK. What do we do instead? Why? Is it good practice to create one constants.h/m? Or is that just another way of masking a global (which is bad)? It does make everything easy to find. Should we create one .h/.m file with multiple constants classes within? I can easily go back to using a .pch, but a clear path forward to the current year’s practice would be nice. Thanks in advance. - Alex Zavatone |
|
Re: Sandboxed WkWebView
Gerriet M. Denkmann
On 18 Oct 2017, at 12:21, Jens Alfke <jens@...> wrote:The reason that I took all this trouble with sandboxing is:On Oct 17, 2017, at 9:14 PM, Gerriet M. Denkmann <g@...> wrote:It sounds like the framework is being too eager to check for this entitlement. It’s definitely worth filing a bug report with Apple! In iOS 11 this shows a cat: htmlString = <h1>Cat</h1><img alt=“Cat” src=“cat.gif” /> [wkWebView loadHTMLString: htmlString baseURL: folder containing cat.gif ] In macOS 12.6 there was no cat, just a blue icon with “?”, probably meaning broken link. So I thought: iOS is sandboxed, so maybe WkWebView needs sandboxing to show cats. But now with sandboxing on macOS I still do not see a cat. Most frustrating. Gerriet. |
|
Re: Sandboxed WkWebView
It sounds like the framework is being too eager to check for this entitlement. It’s definitely worth filing a bug report with Apple! —Jens |
|
Re: Sandboxed WkWebView
Gerriet M. Denkmann
On 18 Oct 2017, at 06:21, Andrew Keller <andrew@...> wrote:I just tried this:That one by itself didn’t change the symptoms of the issue."deny mach-lookup com.apple.nsurlstorage-cache” sounds exactly like the OS denying something because the app isn’t provisioned for that capability, but I’m having trouble identifying which provision I need to turn on in Xcode.I believe URL access requires com.apple.security.files.bookmarks.app-scope entitlement in a sandboxed app. App Sandbox Network [checked] Outgoing Connections (Client) and now it seems to work. Excellent idea! I would never have guessed that an app which does not use any outgoing connections at all needs this entitlement. A million thanks to you! Gerriet. |
|
Re: Sandboxed WkWebView
Gerriet M. Denkmann
On 17 Oct 2017, at 23:37, Andrew Keller <andrew@...> wrote:Regarding: fehler 10:19:55.449646 -0400 sandboxd Sandbox: SandboxedWebView(4372) deny mach-lookup com.apple.nsurlstorage-cache I added in: SandboxedWebView.enttitlements the following item: com.apple.security.temporary-exception.mach-lookup.global-name = com.apple.nsurlstorage-cache which seems to get rid of this error. But the app does not work any better for this. Regarding: fehler 10:19:55.417821 -0400 appleeventsd <rdar://problem/11489077> A sandboxed application with pid 4372, ‘“SandboxedWebView”’,…. This might go away if you run the app not from Xcode, but as /Applications/SandboxedWebView.app I tried this too, but no change for the better. Herzliche Grüße Gerriet.
|
|
Re: Sandboxed WkWebView
Andrew Keller
That one by itself didn’t change the symptoms of the issue."deny mach-lookup com.apple.nsurlstorage-cache” sounds exactly like the OS denying something because the app isn’t provisioned for that capability, but I’m having trouble identifying which provision I need to turn on in Xcode.I believe URL access requires com.apple.security.files.bookmarks.app-scope entitlement in a sandboxed app. However, upon clicking on random buttons on the Entitlements screen, it seems that `com.apple.security.network.client` does make the example app work while sandboxed. I wonder if there is a more specific entitlement that may be more to-the-point, given that this test application does not need to make network calls. Thanks, - Andrew |
|
Re: Sandboxed WkWebView
Marco S Hyman
"deny mach-lookup com.apple.nsurlstorage-cache” sounds exactly like the OS denying something because the app isn’t provisioned for that capability, but I’m having trouble identifying which provision I need to turn on in Xcode.I believe URL access requires com.apple.security.files.bookmarks.app-scope entitlement in a sandboxed app. Marc |
|
Re: Sandboxed WkWebView
Yup. This doesn’t even require messing with symlinks; it’s a supported option in the GUI: - Open Users & Groups system pref - Unlock - Ctrl/right-click a user in the list - Select “Advanced Options” from the context menu - A sheet opens where you can configure the home directory path (and much more) —Jens |
|
Re: Sandboxed WkWebView
Andrew Keller
Now I’m curious. I created the test application as described, and I get the same results (macOS 10.13, Xcode 9). I also see these entries in the system log while the app is sandboxed:
"deny mach-lookup com.apple.nsurlstorage-cache” sounds exactly like the OS denying something because the app isn’t provisioned for that capability, but I’m having trouble identifying which provision I need to turn on in Xcode. Any ideas? Thanks, - Andrew
|
|
Re: Sandboxed WkWebView
Gerriet M. Denkmann
On 17 Oct 2017, at 10:59, Marco S Hyman <marc@...> wrote:My Test app is really simple, just one window (with WKWebView), one framework (WebKit.framework) and one method:This said, the porcupine in my home directory seems to be a red herring:I don’t know if this has anything to do with your issue. #import "AppDelegate.h" @import WebKit; @interface AppDelegate () @property (weak) IBOutlet NSWindow *window; @property (strong) IBOutlet WKWebView *webView; @end @implementation AppDelegate - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { BOOL sandboxed = ![ NSFileManager.defaultManager isWritableFileAtPath: @"/tmp/" ]; NSString *htmlString = sandboxed ? @"<h1>Sand</h1>" : @"<h1>Water</h1>"; NSLog(@"%s %@ will loadHTMLString: \"%@\" baseURL: nil",__FUNCTION__, self.webView, htmlString); WKNavigation *a = [ self.webView loadHTMLString: htmlString baseURL: nil ]; NSLog(@"%s loadHTMLString returned %@",__FUNCTION__, a); } @end No access to any files, whether inside or outside of home folder. Still I have never seen “Sand” in my window. Gerriet. |
|
Re: Sandboxed WkWebView
Marco S Hyman
This said, the porcupine in my home directory seems to be a red herring:I don’t know if this has anything to do with your issue. One difference between a sandboxed and non-sandboxed app is that the “home directory” in a sandboxed app is inside the application container, not the current users home directory. ~/ ==> non-sandboxed home directory ~/Library/Containers/com.example.appid/Data/ ==> sandboxed home directory You will not be able to create/access anything outside of the sandbox container without going through Powerbox or adding appropriate entitlements. Marc |
|
Re: Sandboxed WkWebView
Gerriet M. Denkmann
Some further notes:
toggle quoted message
Show quoted text
NSString *porcupine = @"เม่น"; NSData *utf8Data = [ porcupine dataUsingEncoding: NSUTF8StringEncoding ]; NSString *badPorcupine = [ [ NSString alloc ] initWithData: utf8Data encoding: NSASCIIStringEncoding ]; NSLog(@"NSASCIIStringEncoding \"%@\" → \"%@\"", porcupine, badPorcupine); prints: NSASCIIStringEncoding “เม่น" → "à¹à¸¡à¹à¸" Please note that the path to the home directory is *not* guaranteed to be Ascii: if anything in ”/Users/username” is a symbolic link then this assumption is no longer valid. NSLog(@"home \"%@\"", @"~".stringByExpandingTildeInPath); prints: home "/Volumes/เม่น/Users/gerriet/Library/Containers/de.mdenkmann.TestViewsMac/Data" This said, the porcupine in my home directory seems to be a red herring: Even without non-Ascii characters in the path to the home directory a sandboxed WkWebView just does nothing, while the non-sandboxed version works as expected. Gerriet. P.S. macOS 12.6 On 16 Oct 2017, at 19:23, Gerriet M. Denkmann <g@...> wrote: |
|
Re: Sandboxed WkWebView
Gerriet M. Denkmann
On 16 Oct 2017, at 18:58, Sandor Szatmari <admin.szatmari.net@...> wrote: Do you have a catch all Objc exception breakpoint set?Yes I have, and: No there are no exceptions. I can imaging if the path to the volume is getting mangled and everything ‘seems’ ok that some call is failing and causing your delegate reference to fail. |
|
Re: Sandboxed WkWebView
Sandor Szatmari
One thing that can cause delegate methods to never be called is if there’s been some sort of exception thrown, one that doesn’t crash the app but causes SDK internals to get all mucked up. Do you have a catch all Objc exception breakpoint set? I can imaging if the path to the volume is getting mangled and everything ‘seems’ ok that some call is failing and causing your delegate reference to fail.
toggle quoted message
Show quoted text
Sandor On Oct 16, 2017, at 07:46, Gerriet M. Denkmann <g@...> wrote: |
|
Re: Sandboxed WkWebView
Sandor Szatmari
One thing that can cause delegate methods to never be called is if there’s been some sort of exception thrown, one that doesn’t crash the app but causes SDK internals to get all mucked up. Do you have a catch all Objc exception breakpoint set? I can imaging if the path to the volume is getting mangled and everything ‘seems’ ok that some call is failing and causing your delegate reference to fail.
toggle quoted message
Show quoted text
Sandor On Oct 16, 2017, at 07:46, Gerriet M. Denkmann <g@...> wrote: |
|
Sandboxed WkWebView
Gerriet M. Denkmann
macOS 12.6
When I start my sandboxed app, I get lots of messages like: “could not create “/Volumes/à¹à¸¡à¹à¸/Users/gerriet/Library/Containers/….”." Of course there is no disk-partition called “à¹à¸¡à¹à¸”. And when I check “/Volumes/เม่น/Users/gerriet/Library/Containers/….” all complained about folders have been created. So far so confusing. But when I do [ wkWebView loadHTMLString: … ] I see again: “could not create “/Volumes/à¹à¸¡à¹à¸/Users/gerriet/Library/Containers/de.mdenkmann.TestViewsMac/Data/Library/Caches/WebKit/NetworkCache”" and then nothing happens - no delegate method is ever called and the view remains blank. Any idea what I am doing wrong? Gerriet. P.S. works fine without sandboxing. And WebView works with or without sandboxing. |
|