I know about Sandbox limitations and and my usual technique of having the user save a file is via the NSSavePanel, which automagically grants the app the necessary priviliges to the location, as indicated by the user.
Now, here's the... not-so-uncommon scenario :
User creates a new file, in my app
Saves is for the first time (so, there's a good reason for the NSSavePanel to show up)
Then edits the contents of the document (please, note that my app is not a typical NSDocument-compliant one)
And finally he want to re-save it. (not "Save (it) as.." but just... "Save (it)" - since he's already specified a location, right?)
How is this doable? What's the "approved" way of achieving that? I've read about bookmarks but a) I'm not sure whether it is what I need, b) I haven't managed to find any real code example.
So, any ideas?
Please, note : no-matter-what, the solution must be fully-functional for 10.6 as well.
UPDATE : Hmm... That's just weird (or at least unexpected). Just tried re-saving at a previous location already selected via NSSavePanel and it seems to be working (without doing anything). Is that possible? (And yep, just re-checked it twice : the app is sandboxed)
You provided your own answer - “which automagically grants the app the necessary priviliges to the location, as indicated by the user” - when the user selects the file in the file panel the sandbox is extended to include the selected location and for the rest of the current execution your app my access it.
Related
I've an idea to develop a modification to WhatsApp, for example now when I click attachment symbol it shows only 6 I want to add one more option to it. If it's possible let me know. I want to add more one button on Attach menu.
It is not clear what exactly you are asking.
You have an option to launch other applications from your app.
If you want to change the way a certain app looks, or behaves you have to write something similar to it for people to use, but you cannot change the original app (no one will let you)
Here you go! it's possible, as #Jef said in comments.
using documentation interaction controller.
https://www.whatsapp.com/faq/iphone/23559013
you need to work on how to hook into attachment menu.
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIDocumentInteractionController_class/
There is an assumption in your question that these other apps are put there by the whatsApp developers, or by a third party who was somehow able to modify their code. I suspect that what is happening is that they (whatsApp) simply export a document/file of a certain type (UTI) If your application supports that same UTI it should appear here. So there is six buttons for you, on your phone, but another user might see a different number, it depends entirely what they have installed on their device.
CONCEPTUAL.. if you double click on a file on your computer then the file browser (OS) opens that file with some application or other. Perhaps it is a .doc file and the OS pushes that file to word or pages. Or it may be a .psd file and it gets pushed to photoshop. How does this happen? The OS has a registry (database) of applications for each file type, applications sign up on this when they install/update. If you right click on a file you see an 'open in..' option that lists all your applications which can handle that file type, this is the menu that you are wanting to get onto (for whatsApp's file type) imho.
So you need to
1 ascertain what file type (UTI) WhatsApp is exporting
2 declare support for that file type in your application (this is the bit which will be platform specific solution) (iOS docs https://developer.apple.com/library/ios/documentation/FileManagement/Conceptual/DocumentInteraction_TopicsForIOS/Articles/RegisteringtheFileTypesYourAppSupports.html#//apple_ref/doc/uid/TP40010411-SW1 )
**edit/addition
3. add the code to actually handle the file when your app receives it. On iOs this is in the appDelegate in
-(void) application: openURL: sourceApplication:annotation:
If the Whatsapp people have published an API then thats where you want to look. Good luck
Here's a though question:
I need to find out when the user double-clicked the OS X desktop, but not icons on it.
Now, I have thought of the following solutions, though I am not sure if they are doable:
Using desktop icons position (not sure how to get them), and the size of the desktop icons, we could theoretically check once the user double-clicks on the desktop, if it is inside one of the icon areas. Contra: Might not be flawless as some icons might be transparent or not taking up the entire icon size.
Maybe there is a variable that tells us if a icon from the desktop has been clicked? Then we could just check if that variable has been activated when the user double-clicked the last time the desk.
I am certainly still open to other (better) solutions, but they need to be sandboxable for the Mac App Store.
This is probably not going to be appropriate for the Mac App Store, for a number of reasons.
First, how are you going to intercept clicks outside your window? There are a few different mechanisms for this (e.g., event taps), but none of them are allowed in sandboxed apps. And that's intentional, and for a good reason—you're not supposed to be interfering with other apps or with the OS.
On top of that, it's hard to imagine that whatever you're trying to do wouldn't count as non-standard UI/HIG stuff, which is another reason for rejection.
But, assuming none of that were a problem, and you could intercept clicks on the desktop, there's no documented way to get all the icons on the desktop, so you have to read the .DS_store file directly, which means relying on private implementation information, which is another thing you're not allowed to do.
Finally, you have to get access to that .DS_store file. Unless you're expecting the user to drag the (invisible) file or its parent directory to your app or select it in an NSOpenPanel or something, the only way to get such access from inside the sandbox is via a temporary exception entitlement. Which you can't use unless you can justify to the reviewer why you need it as a workaround for a bug or limitation in the OS. So, what's your justification going to be?
I'm developing an app that is currently sandboxed. It acts as a basic text editor. Recently, I wanted to test what happens when I open a file in my app and another app at the same time, make an update in one app, then then see the updated in the other. I'm using Coda or BBEdit as my alternative editors. If I turn off sandboxing -- then this issue does not exist. However, since apps are required to be sandboxed as of March 1, I would rather implement a solution rather than wait and see.
When I open both files and make an edit in my app and then switch to the other app, the changes are reflected so that those editors have the version just saved from my app. However, if I perform the converse of saving from their app and then moving to mine -- no joy. Without performing any action, the console reports two specific errors: deny file-issue-extension and deny file-write-data. The app appears to be losing privileges to edit the document since it was changed by an external editor after the document was opened in my app. If I try to save the file in my app, it asks to duplicate the document because it has lost access to the original document. This doesn't happen the other way around because those apps have not been sandboxed and therefor have permissions that my app does not. It also doesn't appear that you can prevent the other app from making the changes if you don't want this behavior.
The documentation on developer.apple.com mentions nothing of this type of situation. I am not sure if this is intended behavior. If it is, then I can just tell my user that the document permissions have been lost and they should either save a new version or re-open the file. If it is NOT intended behavior, then what method in the NSDocument API would grant permission to the file once it has been lost? I'm assuming the answer is the former, that this is intended, but can anyone confirm and is there documentation?
Without performing any action, the console reports two specific errors: deny file-issue-extension and deny file-write-data. The app appears to be losing privileges to edit the document since it was changed by an external editor after the document was opened in my app. If I try to save the file in my app, it asks to duplicate the document because it has lost access to the original document
The correct behavior in a situation like this is to not overwrite the file, but to prompt the user if they want to reload the document, if so reload it and then write it.
The OS is doing the right thing by not allowing a blind write over a file that has changed.
See NSFilePresenter - (void)presentedItemDidChange to see if it changed. Reread the file and then see if you can save it. You dont say you have been denied a read on the file.
Also, since you havent posted any code it might be helpful to show what code you are using to access the file and to save it. NSDocument has built in handling for some types of file changes in the sandbox.
Lets call your App ScottEdit and your competitor as StackEdit
There could be several things going on. NSDocument has a lockDocument method. StackEdit may have locked the document and did NOT unlock it after save. If you quit the app, the file should be unlocked and available for your app. If this is the case, you will need to create a notification for when the file attributes change using kqueue or another.
If the other app is "blocking" access to your app. You can send an email to that developer and ask him to update his app so it unlocks the document after save. This last step is in addition to setting up notifications because another developer may come along and do the same thing (breaking your app).
I am building a multitasking application which includes a functionality for viewing large pdf files. In order to avoid downloading the file each time the user wants to view the file, i download the file in the NSTemporaryDirectory and use the UIDocumentInteractionController to provide "Quick Look" and "Open in iBooks".
I wish to clear all temporary files when the user exits the application in order to avoid consuming space on user's device. Since my application is multitasking and my applicationWillTerminate method never gets called, the files are never deleted. When is it best to clear the NSTemporaryDirectory and how can i do it? Am i missing something?
Thanks in advance
You can make use of an old UNIX trick that also works fine on iOS (I know since I make use of it):
Save the files.
Open them.
Remember the filedescriptors.
Delete the files (this is the magic part).
The effect is that the files remain open as long as you don't close them. But their directory entries are gone, i.e. the files won't show up in a directory listing any more. The cool thing is now that as soon as you close one of those filedescriptors the corresponding file automatically gets completely deleted from disk. It doesn't matter whether you explicitly call close on them or whether your app terminates or crashes, in all those cases the files get deleted by the OS and you don't need to worry about it.
The downside is that you need to change your code so that it can work with the filedescriptors as you cannot access the files by name any longer.
applicationWillResignActive
in your Appdelegate is the best place to do.
This is pretty weird and I would very much appreciate all help =)
I have a document based app where it should be possible to perform some actions on the document file. To do so I'm saving the document every time the document actions are called. To do so I'm using the method:
saveDocumentWithDelegate:didSaveSelector:contextInfo:
The problem is, that when closing the document, reopening it from the recent files menu and then performing the action again I'm being presented with the dialog box saying that
This document’s file has been changed by another application since you opened or saved it.
However this is not the case when using the save menu item.
I've tried with different save methods:
saveToURL:ofType:forSaveOperation:error:
And even though this results in the behavior I'm looking for there is a side effect: The save menu item becomes deactivated after performing the action.
So my question is: How should I correctly perform save operations programmatically? I've looked through the docs but I haven't seen anything which looks like an obvious solution.
All help is appreciated. Thanks
I found solution for this problem in my case.
Problem was in options in overriding of configurePersistentStoreCoordinatorForURL:ofType:modelConfiguration:storeOptions:error: method of NSPersistentDocument. Problem was solved when I delete string
[options setObject:[NSNumber numberWithBool:YES] forKey:NSSQLiteManualVacuumOption]
I used vacuum option for some reason. Don't know how but it caused problem with saving. When I refused this option the problem has disappeared.
To get it to work as you want, you can probably fix it by using the saveToURL:... method and then call -[NSWindow setDocumentEdited:] or -[NSDocument updateChangeCount:] which will stop the menu item from being disabled.
However, I'm not sure your overall approach is right. If you have a save menu item, I don't think you should be saving automatically unless you're using Lion’s auto-save feature (recommended) in which case you would call different methods.
And even if you did decide to stick with the auto-saving as you have it now, why wouldn’t you want the menu item to be disabled? It’s disabled because there are no changes to save.
Why are you auto-saving the file anyway?