I have a problem with programmatically deleting files that reside on an external disk,which must be accessed using security-scoped bookmarks.In my app, I collect lists of files that reside on an external disk.After the user has opened the directory of the files, I create a security-scoped bookmark like this: directoryBookmark_ = [dir bookmarkDataWithOptions: NSURLBookmarkCreationWithSecurityScope
includingResourceValuesForKeys: nil
relativeToURL: nil
error: &systemError];Next time, the app runs, I resolve the bookmark like this: directoryLocation_ = [NSURL URLByResolvingBookmarkData: directoryBookmark_
options: NSURLBookmarkResolutionWithSecurityScope
relativeToURL: nil
bookmarkDataIsStale: & isStale
error: & error];
[directoryLocation_ startAccessingSecurityScopedResource];(directoryBookmark_ is saved and loaded in the user preferences.)At some later point, my app wants to delete one of the files in that directory (or sub-directory),like this: NSString * abs_path = [self absolutePathFor: filename_];
BOOL success = [self deleteFile: abs_path ];This does not work. In the log, I get the error message:Failed to delete /Volumes/.../image.jpg: “image.jpg” couldn’t be moved to the trash because you don’t have permission to access it.!I then try to get more info about the problem using this code: NSURL * imgurl = [NSURL fileURLWithPath: abs_path isDirectory: NO];
NSError * error;
NSFileHandle * fileHandle = [NSFileHandle fileHandleForUpdatingURL: imgurl error: & error];But it always returns a valid fileHandle, i.e., there is no error.I selected "Read/Write" in the "User Selected File" entitlement of my app.Of course, everything works fine when the files reside on my local disk (even across multiple invocations of the app).The external disk is just a hard disk connected via USB to my laptop.Deleting the files manually on the external hard disk works, of course.Does anyone have an idea what mistake I might be making?Or is there a way to get the necessary permission?Surely, apps must have a way of deleting files programmatically, don't they?At least, appe's docs don't mention anything indicating otherwise.All hints and insights will be highly appreciated.
Post
Replies
Boosts
Views
Activity
I am beginning to pull out my hair: I am trying to create a subview programmatically that would adjust its size automatically when the user resizes the window. More details below.I have searched the documentation (e.g., Apple "Auto Layout Guide"), searched the internet (and tried to follow a lot of examples on stackexchange), all to no avail.More specifically, I have a very simple setup that consists of a MasterViewController that has its own XIB.It's declared like this:@interface MasterViewController : NSViewController
{
ArtSaverView * saver_;(there is not much more to it)It creates a subview programmatically that is an instance of my own class ArtSaverView, which is a subclass of ScreenSaverView, which is a subblass of NSView.So, my MasterViewController has this method:- (void) viewDidLoad
{
[super viewDidLoad];
saver_ = [[ArtSaverView alloc] initWithFrame: self.view.frame isPreview: NO ];
[self.view addSubview: saver_];Now, when the user resizes the window, the view of the ArtSaverView instance does not resize, no matter what I do.For instance, I have tried this later in the method viewDidLoad: [saver_ setTranslatesAutoresizingMaskIntoConstraints: NO];
NSDictionary * views = NSDictionaryOfVariableBindings( saver_ );
NSArray * horizontalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[saver_]-0-|"
options: 0 metrics: nil views: views];
NSArray * verticalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[saver_]-0-|"
options: 0 metrics: nil views: views];
[self.view addConstraints: horizontalConstraints ];
[self.view addConstraints: verticalConstraints ];
[NSLayoutConstraint activateConstraints: horizontalConstraints ];
[NSLayoutConstraint activateConstraints: verticalConstraints ];But nothing changes.Is there anything else I can try?All kinds of hints, insights, pointers will be highly appreciated.
On the WWDC 2020 page ( https://developer.apple.com/wwdc20/ ) , I found the notice at the bottom that one can request a appointment with an Apple engineer for one-on-one technical guidance.However, being new in this space, I could not find out how to do that.(Yes, I do have a Apple Developer Program membership.)Could some kind soul enlighten me?Thanks a lot in advance.
I have an app that works like a slideshow.
The app works on macOS Catalina, and it is sandboxed.
Now, I would like to provide a mode for running it in "kiosk mode".
Requirements: Run in fullscreen
Disallow app switching, quitting, etc.
Accept keyboard events
The currently logged in user should be able to gain full access by authenticating themselves.
I have tried to add this code to my AppDelegate:
NSApplicationPresentationOptions presentationOptions =(NSApplicationPresentationHideDock | NSApplicationPresentationHideMenuBar | NSApplicationPresentationDisableAppleMenu | NSApplicationPresentationDisableProcessSwitching | NSApplicationPresentationDisableForceQuit | NSApplicationPresentationDisableHideApplication );
NSDictionary *fullScreenOptions = @{ NSFullScreenModeApplicationPresentationOptions: @(presentationOptions) };
[self.window.contentView enterFullScreenMode: [NSScreen mainScreen] withOptions: fullScreenOptions ];
It does provide kind of a kiosk mode, but my app does not receive any key events any more.
It does not matter whether I put this code in -awakeFromNib or in -applicationWillFinishLaunching or in -applicationDidFinishLaunching, I always get the "Funk" sound.
Of course, when I omit the above lines of code, everything works fine, i.e., I receive key events as usual.
I could switch to fullscreen just by calling
[self.window toggleFullScreen: nil]
but then I don't have the kiosk mode precautions, like preventing the user from switching to other apps.
The second problem I am facing is this:
I would like to allow users to quit the app, provided they can authenticate themselves (requirement #4).
There used to be an API ( https://developer.apple.com/documentation/security/authorization_services ),
but it is not available in a sandboxed app. (I don't get Apple's reasoning, but oh well ...)
Question is: is there any way to achieve what I want?
I am still fairly new to Swift, so please bear with me.
I have this piece of code:
var win_name : String? = winInfo[kCGWindowName as String] as? String
if ( win_name == nil )
{
win_name = winInfo[kCGWindowOwnerName as String] as? String
}
if ( win_name == nil )
{
	 win_name = "???"
}
// from here on, we know win_name is non-nil
After the last line, there are many more lines where I need to do access win_name lots of times. Each time I have to write win_name! .
Is there a way to tell the compiler that after line 10, win_name is always non-nil, so that I don't have to force-unwrap it every time?
I could use something like
guard let win_name_nonnil = win_name else { return }
at line 10, but IMHO that would make the code after line 10 even uglier.
Insights will be highly appreciated.
I would like to publish my app on the Mac App Store (MAS).
Unfortunately, I haven't had the time yet to I18N it, yet.
So, what I would like to do is: distribute my app on all english-speaking MAS' (US, UK, Canadian, Australian)
Provide a link on the app's home page that would lead potential users automatically to the US version of the MAS, regardless of their country-specific MAS.
(I would tell users, of course, that the app is only available in English.)
Is that possible?
Best regards, Gabriel
Is there a limit on the number of attempts to upload an App Preview in App Store Connect?
I have been trying to upload an app preview for my new macOS app, each time I received an error (wrong audio format and the like).
Now, the web front end in Safari doesn't even begin to upload the movie! When I click on "Choose File" under "App Preview and Screenshots", I can select the file on my disk, then click "Choose", and then nothing happens at all.
I have already tried logging out and in, of course.
Any ideas would be much appreciated.
I am beginning to pull my hair out.
Best regards, Gabriel
I'd like to upload my app to the Mac App Store and give only a few select testers access to that version on the MAS?
Is that possible?
I have a strange error when resolving a security-scoped bookmark (SSB) in my screensaver.
The code works fine for almost all users (even under Mojave), except for one user under Mojave (10.14.6).
Here is the code in question:
NSError * error;
BOOL isStale = NO;
NSURL * dir_location = [NSURL URLByResolvingBookmarkData: bookmark
options: NSURLBookmarkResolutionWithSecurityScope
relativeToURL: nil bookmarkDataIsStale: & isStale
error: & error];
The method returns NULL, and error says:
Error Domain=NSCocoaErrorDomain Code=259 "The file couldn't be opened because it isn't in the correct format."
The SSB points to a directory in the user's home.
I can see that in the log, because in my code I do
NSDictionary * dict = [NSURL resourceValuesForKeys: [NSArray arrayWithObjects: NSURLPathKey, nil]
fromBookmarkData: bookmark ];
and then I output [dict objectForKey: NSURLPathKey] .
The user has opened the directory in the previous run, and I am creating and storing an SSB with this code:
NSError * systemError;
NSData * dir_bookmark = [dir bookmarkDataWithOptions: NSURLBookmarkCreationWithSecurityScope
includingResourceValuesForKeys: nil
relativeToURL: nil
error: &systemError];
and it seems to work just fine.
I don't know whether or not it matters: the error occurs in a screensaver of mine, i.e., it occurs when the users launches the screensaver moving the mouse into the respective hot corner.
But the SSB is created and resolved by exactly the same .saver executable.
Does anyone have an idea why -URLByResolvingBookmarkData might fail?
Or could some kind soul give me hints how I might be able to track down the bug?
(Of course, I tried to google, to no avail.)
I am at a loss here ...
Thanks a lot in advance.
Best regards, Gabriel
I haven't tried screensavers in a while. Now, under macOS 11.6, it appears that screensavers don't stop when I press a key (any key, even Esc), or move the mouse.
This happens with the built-in screensaver , such as "Flurry" and others.
The only way to escape from screesavers seems to be a mouse click.
I was wondering if this is intentional by macOS or if I screwed up the settings of my Mac.
If it is intentional, I was wondering what is the rationale behind that change? (it used to be the case that screensavers would stop immediately when the user pressed a key or moved the mouse).
If it's my settings on my Mac, which one could it be?
Way earlier, under Catalina and before, it used to be the case that screensavers could receive keyboard events and act upon them. Did Apple bring that back?
I am asking all this because I am developing a screensaver myself.
I have an app on the app store that costs a few bucks.
Also, some users have received a free beta version outside the app store (so they could help me with testing).
One of those users now would like to review my app on the app store, but, naturally, he wouldn't want to buy it on the app store, since his free copy works fine.
Is there a way for him to still write a review on the app store?
Can I maybe generate a token/code so he could download the app from the app store for free, so that he can then write a review?
Or is there any other way?
Best regards, Gabriel
Does anyone know if it is possible to run applications built on top of Unreal Engine (version 5) on the Vision Pro?