I am building a iOS 5.1 app using storyboard. this app contains a table view. My idea was to add an "add" button to my title bar, in the table view. When a user clicks on the add, a simple document editor I need to build (like keynote or pages) will open. when the user clicks on the save button, the file will be uploaded possibly on I cloud, and all other users of the application will be able to access it, from a downloads tab, download it, and add it to their own app (a sort of file sharing via iCloud). Is it possible to do something like that? How can I do it? Can I do it using iCloud, or do i need to build my own database?
maybe you should try to use this:
NSURL *urlToShare = ...; NSDate *date;
NSError *error;
NSURL *sharedURL =
[[NSFileManager defaultManager] URLForPublishingUbiquitousItemAtURL:urlToShare
expirationDate:&date
error:&error];
Thats from CS193p lessons. This code will help you to share files between different iCloud Accounts.
But remember that "Only files (not directories) maybe exported in this way.
The URL points to a copy of the file (so it is a read-only sharing mechanism)."
Hope this helps!
Related
My app is an image viewer for iOS. I allow users to pick files from the camera roll or cloud file providers. For each file chosen, I create a bookmark so that the user to come back to view the file later without having to go through all of the steps of the camera roll/cloud file pickers again. The camera roll bookmarks work consistently, but the cloud file provider bookmarks fail randomly by returning nil from the call to URLByResolvingBookmarkData. The error returned is:
"File Not Found"
This happens with files from iCloud, DropBox, Box, Google Drive, etc. Here is how I create and retrieve the bookmarks:
// bookmark created from url returned by UIDocumentPickerViewController
NSData *bookmark = [url bookmarkDataWithOptions:options includingResourceValuesForKeys:nil relativeToURL:url error: nil];
// retrieving the URL from this bookmark works for a short time, then returns nil
url = [NSURL URLByResolvingBookmarkData:bookmark options:NSURLBookmarkResolutionWithoutUI relativeToURL:nil bookmarkDataIsStale:&isStale error:&error];
Anyone can shed some light as to why a bookmark will work for a while, then fail? Limited storage/RAM?
I have a feeling that the answer is to keep a local copy of files from cloud storage since they're not guaranteed to be accessible more than once.
You should use startAccessingSecurityScopedResource on the URL, making sure to call stopAccessingSecurityScopedResource when you are finished.
Alternatively, Apple highly recommend using FileCoordinator or UIDocument to manage access to files. Especially now you may access files that other apps are also accessing.
I checked the latest Dropbox and Excel for iOS. In Dropbox we get an edit button. On click it opens Excel's extension where you can edit the file.
After save, changes are reflected in the Dropbox file too.
I want to add such a button. Also I'd like to add such a button to images to open them in available "photo editing" apps.
How to check if file (image, xls, doc or any other) can be opened to edit?
Code so far:
UIDocumentPickerViewController *documentPicker = [[UIDocumentPickerViewController alloc] initWithURL:url inMode:UIDocumentPickerModeExportToService];
documentPicker.delegate = self;
documentPicker.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:documentPicker animated:YES completion:nil];
Also tried changing mode to UIDocumentPickerModeMoveToService...
As per apple docs
Move a local document. The user selects an external destination. The document picker moves the document; however, you can still access the document as an external document, letting the user edit the document in place.
But I tried all four modes. Did not show excel option.
UIDocumentPickerModeImport,
UIDocumentPickerModeOpen,
UIDocumentPickerModeExportToService,
UIDocumentPickerModeMoveToService
The only way to communicate with other iOS apps "locally" is using what is called URLSchemes.
This is the documentation to use URLScheme with the MSOffice apps.
https://msdn.microsoft.com/en-us/library/office/dn911482.aspx
Answering the specific question:
How to check if file (image, xls, doc or any other) can be opened to edit?
You can use the UIApplication method called canOpenURL to check if the current device responds to a specific URLScheme and if it does, you can call the app to edit you file. The same can be applied to other apps that you want to open. You just need to see if the app have URLScheme support.
Remembering that in iOS 9 you need to add the URLs you want to call during the app life in the Info.plist. Otherwise, the canOpenURL method will always returno NO.
This code illustrates the approach. However, it is to search some navigation apps. Just like tapping a shared friend location in WhatsApp.
https://snipt.net/wallaaa/using-url-schemes/
The result:
it's 2017 and iOS 11 and it's still not possible to edit files in place.
Dropbox is using MS Office API to provide http links to download and upload changed document.
Direct edit of the file is only possible if FileProvider extension is implemented and file was opened in editor app via document picker (which grants access to the file in sandbox).
Photo editing is allowed because editor is made by Apple (Photos app).
I am implementing Music Player application in iOS platform. Here I am storing and retrieving the media contents using Documents directory. So I can't able to access the 'Documents Directory' when iPhone is getting locked with passcode. I referred Apple developer library, they said the Encryption & Decryption is comes under the accessing the file contents from documents directory. So if device is getting locked the Decryption key is Destroyed. Here I have attached the Screen shot of Problem Description. I was stuck with this problem last 2 months. Pls give me any other ways to access the Documents directory at locked state. Not Only Media , Any other content*.
Thanks in Advance.
Apple Developer Site:
https://developer.apple.com/library/mac/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html
You need to specify the file protection level as an option when you write your files. Example:
[someData writeToFile:filePath options:NSDataWritingFileProtectionNone error:&error];
In this, someData is an NSData representation of the data you want to write to disk, filePath is the string path where you want to save the file.
Read the documentation on NSDataWritingOptions in the NSData Class Reference for more encryption options.
The Apple Docs say that UIDocumentInteractionController "provides in-app support for managing user interactions with files in the local system". Is there a similar setup for viewing files on a server? I tried just sending the link to the file as the NSURL for interactionControllerWithURL:, but that didn't work. I guess the alternative would be to download the file, then open it once it has downloaded, then delete the file. That seems like a lot of extra coding work though, if there is an easier way that's already available.
Edit: I already know the name of the file I want to view/download, so I'm not really looking for the "file list" aspect of UIDocumentInteractionController. On the server, there are many Google Earth .kml files. The user isn't going to directly select which file to open from a list - I select the file to open programmatically based on actions taken by the user previously in the session.
As I understand it, presentOpenInMenuFromRect:inView:animated: will show a popover something like "Would you like to open the file 'myFile.kml' in Google Earth?". If the user selects 'Yes', the UIDocumentInteractionController launches Google Earth and opens myFile.kml. So I guess I'm not really looking for a file list viewer, just a way to trigger an "Open With" kinda functionality, where the file I'm opening exists on my server.
UIDocumentInteraction controller can't be used to view list of files present on server.
UIDocument interaction controller takes local file present in source application and shows list of applications that can open that file.Once use clicks on file then it is transferred to target app.
If you want to get file from server then you can use NSURLConnection class to download file form server and store it on device.
I think I figured this out. I don't need to use a UIDocumentInteractionController at all for what I'm looking for. I can simply
NSURL *url = [NSURL URLWithString:#"comgoogleearth://www.mysite.com/myfile.kml"];
BOOL canOpen = [[UIApplication sharedApplication] canOpenURL:url];
if (canOpen)
{
[[UIApplication sharedApplication] openURL:url];
}
else
{
NSLog (#"Open failed. Make sure Google Earth is installed and the URL is correct.");
}
This will launch Google Earth with my file just like I'm looking for.
FYI, I got the scheme for Google Earth from elpsk's answer to this question. It looks like a pretty comprehensive list of a lot of file types and the apps that open them. Just replace the comgoogleearth in my URL with the scheme for whatever app you are trying to open a file with.
i have developed an app that can download mp3 files (nearly 6 to 8 mb of size) from online and stored in NSDocumentDirectory. my app get rejected today and says that
"Apps must follow the iOS Data Storage Guidelines or they will be rejected"
We found that your app does not follow the iOS Data Storage Guidelines, which is
required per the App Store Review Guidelines. The iOS Data Storage Guidelines
indicate that only content that the user creates using your app, e.g., documents,
new files, edits, etc., may be stored in the /Documents directory - and backed up
by iCloud.
Temporary files used by your app should only be stored in the /tmp directory;
please remember to delete the files stored in this location when the user exits
the app. "
i used to store the music files in NSDocumentDirectory .
so, this is the first time am doing this, i cant figure out the actual problem. what should i do to resubmit my app for acception.
here is my code
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectoryPath = [[paths objectAtIndex:0]stringByAppendingPathComponent:[NSString stringWithFormat:#"psalmsMusic%d.mp3",i]];
NSLog(#"ddddddd psalmsMusic%d.mp3",i);
i++;
NSLog(#"path %#",documentsDirectoryPath);
[receivedData writeToFile:documentsDirectoryPath atomically:YES];
really need some help.
i got my app rejected for the same reason , the solution is really simple instead of saving your downloaded files to the Documents directory you have to save them to the Cache directory which is a temp directory that don't get backed up to iCloud and can be randomly deleted by the OS on certain occasions ... this is how you save a file to the cache directory
NSString *filePath = [[self applicationCachesDirectory] stringByAppendingPathComponent:fileName];
BOOL flag = [[NSFileManager defaultManager] createFileAtPath:filePath contents: receivedData attributes:nil];
EDIT
NSString *filePath = [[self applicationCachesDirectory] stringByAppendingPathComponent:[NSString stringWithFormat:#"psalmsMusic%d.mp3",i]];
NSLog(#"ddddddd psalmsMusic%d.mp3",i);
i++;
BOOL flag = [[NSFileManager defaultManager] createFileAtPath:filePath contents: receivedData attributes:nil];
if ( flag )
NSLog("success");
Once the iCloud is implemented in Apple, The Document directory data is somehow related with iCloud Storage. Hence Apple is now rejecting the applications using heavy data storage in document directory.
You need to store the data at some other location. Store MP3 files At some other location.
This link May Help You.
http://www.techotopia.com/index.php/Working_with_Directories_on_iOS_4_%28iPhone%29
I Hope it'll Solve your problem.
Another is following..........
The iOS Data Storage Guidelines indicate that only content that the user creates using your app, e.g., documents, new files, edits, etc., may be stored in the /Documents directory - and backed up by iCloud.
Temporary files used by your app should only be stored in the /tmp directory; please remember to delete the files stored in this location when the user exits the app.
Data that can be recreated but must persist for proper functioning of your app - or because customers expect it to be available for offline use - should be marked with the "do not back up" attribute. For NSURL objects, add the NSURLIsExcludedFromBackupKey attribute to prevent the corresponding file from being backed up. For CFURLRef objects, use the corresponding kCFURLIsExcludedFromBackupKey attribute.
See http://developer.appcelerator.com/question/134926/ipad-app-rejected-ios-data-storage-guidelines for details.
Apple wants to reduce the size of your backup footprint.
First, stop using Documents. It's not appropriate.
If you are able to download the files again reasonably easy, you should store them in a place they won't be backed up. I suggest Caches. If they're purged, you should just download them again.
If it is difficult to download them again, you should store them somewhere else in the Library folder.
You can find the Caches directory using:
NSArray *paths = NSSearchPathForDirectoriesInDomains(
NSCachesDirectory, NSUserDomainMask, YES);
Basically, this is what you have now, but instead of NSDocumentDirectory you use NSCachesDirectory.
If you control the filenames, this is fine as is. If you don't, you should probably create a subdirectory and work from there so you don't collide with anything.
You can not store in NSDocumentDirectory because this directory is for syncing with iCloud now. But you can use NSCachesDirectory or use temp directory as apple comment states for store music file.
the guidelines says that only important files that can't be recreated ( downloaded ) from the internet should go to the Documents Directory because this is t
As per the iOS Storage Guidelines (which can be found at http://developer.apple.com/icloud/documentation/data-storage/) you should put all user-generated content in the Documents directory and all re-downloadable content in the Caches directory. So you should be fine putting the sqLite database there.
The background on this is that starting with iOS 5 the Documents directory is backed up to iCloud. As a lot of apps tend to store their complete data there the iCloud backups get rather large, which uses up the free space and creates network traffic, both of which in turn anger the user because he/she wonders why. To mitigate this Apple now seems to take a much closer look on what is saved into the Documents directory and if this is possibly regeneratable content (e.g. downloadable files).
Beware, that the Caches directory can and will be purged on iOS 5 by the operating system at times when the free space on the device gets low. Thus your app cannot longer just assume that everything is there as it was before but you rather have to re-check every time you access something out of your cache.
Hope this helps...!
my app also got rejected because of same reason - (2.3)
try this -
NSString *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
The advantage of this whenever your device will Sync with cloud , at that time the application data will not synch because its in NSCachesDirectory instead of NSDocumentDirectory.
And Disadvantage is that whenever you will use your device and if you have less memory in your device. then CPU will might be clear cache for getting free space. so if you have any data for offline use, you might be loss.
2) If you can't use NSCachesDirectory (may be because your data is too important) then you can go with this way -
use this method and give your database path - 'addskipbackupattributetoitematurl'
go through this link - How to use addSkipBackupAttributeToItemAtURL API?