What I Have Done:
I'm developing an application where it transfers different type of files (Eg: Images, Word Docs, Videos) between iOS devices. I'm keeping those files inside the app. I have successfully implemented iCloud Drive to share files from other applications (Eg: Documents). This is how it's done,
UIDocumentPickerViewController *documentPicker =
[[UIDocumentPickerViewController alloc] initWithDocumentTypes:
#[(__bridge NSString *) kUTTypeContent,
(__bridge NSString *) kUTTypeData,
(__bridge NSString *) kUTTypePackage,
#"com.apple.iwork.pages.pages",
#"com.apple.iwork.numbers.numbers",
#"com.apple.iwork.keynote.key"]
inMode:UIDocumentPickerModeImport];
documentPicker.delegate = self;
documentPicker.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:documentPicker animated:YES completion:nil];
[documentPicker release];
Objective:
I want to make my application files (Eg: Images, Word Docs, Videos) store inside the folder "Documents/Files" to be accessible via another app (Like Documents).
R & D:
This is the reference doc I'm reading to achieve this. I manage to create a folder of my app by editing the info.plist. But couldn't display my files stored inside documents directory.
Questions:
Is it possible to make the files I have stored inside documents directory visible to another app via UIDocumentsPicker or something else?.
If it is possible, is there a much easier reference document for me to read? (The current one that I'm reading is a bit difficult to understand).
Thanks.
Related
I am writing an iOS plugin for Unity in Objective-C. I have created a DocumentPicker which allows me to select Folders. However, it does not seem to have access to Third-party storage (such as OneDrive, DropBox, etc).
I am certain I have the permissions for this, because I have also created a DocumentPicker within the same Application which allows me to select Zip files; the Zip file DocumentPicker has no problem browsing these third-party storage areas.
Here is how I am declaring the DocumentPicker instance for Folder selection:
[[UIDocumentPickerViewController alloc] initWithDocumentTypes:#[#"public.folder"] inMode:UIDocumentPickerModeOpen];
Likewise, here is the fully-functioning declaration for the Zip file selection:
[[UIDocumentPickerViewController alloc] initWithDocumentTypes:#[#"public.zip-archive"] inMode:UIDocumentPickerModeImport];
Here is a screencapture of inaccessible Third-party storage in grey, while local storage and iCloud remain accessible in white
I thought perhaps Microsoft, Google, etc, haven't implemented a Document Provider extension for Folder selection, but that seems a bit of a stretch.
Can anyone tell me what I'm doing wrong? Thank you.
According to this post it is not implemented by Dropbox, so one could assume this is the same issue with OneDrive, etc.
Basically, I have 2 projects running, one is in obj-c and another is in Swift 4 and I want them to access their directory folder in order to exchange their resources in the run-time. Right now my approach is accessing document directory of Swift 4 project via:
FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
so it will generate the path like:
/Users/public1/Library/Developer/CoreSimulator/Devices/22D423BD-C28D-45B7-A976-D9FB02409988/data/Containers/Data/Application/3B15E00A-910B-420E-8047-99F2E6E5013D/Documents
And if I want get the same Documents directory of obj-c project, I will use above path, delete 2 last components path:
/Users/public1/Library/Developer/CoreSimulator/Devices/22D423BD-C28D-45B7-A976-D9FB02409988/data/Containers/Data/Application
then using enumerator.nextObject() to find the flag of obj-c project. It works perfectly fine in simulator but in the device, those code counters a problem is that when running on a device, those folders won't be on the macOS folders but in device folders, so the URLs executes by above code is something like:
/var/mobile/Containers
and I neither can find nor access to that folder so that my enumerator won't work. So is there a way to accessing that folder (using code) or some mechanism to get 2 project folder shared with each other?
=========================================================
EDIT: for using AppGroup I added those code in my Obj-C project:
NSUserDefaults *pathShared = [[NSUserDefaults alloc] nitWithSuiteName:#"com.example.myDomain"];
[pathShared setObject:directoryPath forKey:#"path"];
and in Swift 4 code:
let userDefault = UserDefaults(suiteName: "com.example.myDomain");
let path = userDefault?.object(forKey: "path");
but it didn't seem to work...
A language that you are using to implement application is not a reason. It is just a different applications with different sandboxes. In iOS one application can't get access to files from a sandbox of other application. You can share data between applications by using same AppGroup for the applications, after that you can use shared UserDefaults and write and read files from a shared directory:
<...>
NSUserDefaults *mySharedDefaults = [[NSUserDefaults alloc] initWithSuiteName: #"com.example.domain.MyShareExtension"];
[mySharedDefaults setObject:theAccountName forKey:#"lastAccountName"];
<...>
NSFileManager* fileManager = [[NSFileManager defaultManger];
NSURL* url = [fileManager containerURLForSecurityApplicationGroupIdentifier:[self appContainerName];
<...>
On iOS, the sandbox will prevent your app from accessing any other app's data, even if you developed the other app yourself, too. However, you can set up an App Group and entitle both of your apps to access it, and that will allow you to share what you want. The Sharing Data with Your Containing App heading on this page has a good overview on how to do that
I need to open a locally saved file in my documents directory in Microsoft Word for doc files or PowerPoint for ppt files.
I've used the UIDocumentInteractionController which works to open these documents, problem is that the client doesn't want to show all the options to open the document and restrict it just to Word or PowerPoint.
self.docController = [UIDocumentInteractionController interactionControllerWithURL:attachmentURL];
So then I used the UIActivityViewController to restrict the options, but without even using UIActivityViewController.excludedActivityTypes the Microsoft options no longer appear using the same NSURL.
self.activityViewController = [[UIActivityViewController alloc] initWithActivityItems:#[attachmentURL] applicationActivities:nil];
Not sure what I'm missing? Or is it possible to open the documents without using either of these classes?
I have an app that downloads a whole bunch of data from over 100+ APIs upon successful login. I successfully download the data, and then use iExplorer to extract the data container folders (Documents, Library and Tmp) from the fully loaded application.
I would like to take a blank version of the original app, in .ipa format, and insert those data container folders into that fully loaded .ipa file. Then I will be able to take this new fully loaded .ipa, and use a deployment software to deploy it to a bunch of local user's devices. So everyone will have this fully loaded app.
Please, has anyone done this? Please provide some feedback, and don't argue with my methodology, because this has be done this way due to requirements. Maybe there is a step I'm missing? I'm not sure.
With the source code in hand, you can run the app in the simulator (no need for iExplorer), wait for it to download all the files and browse to the folder on your computer where the app was installed.
From there you can put aside any files you want along with their respective folders. If you're using Coredata there should be a SQLITE database file there somewhere (typically in your Application Support folder) and this might be all you need but it is hard to tell without looking at your implementation details.
Once you have the files you need set aside, add them to the app bundle via Xcode and create code to check whether files already exist (in which case you don't want to replace them), and if not copy all files needed from the bundle into their respective folders.
Here's some semi pseudo-code for you:
NSDictionary *userPrefs = [[NSUserDefaults standardUserDefaults] objectForKey:self.email];
if (![userPrefs[kInitialSetupCompleted] boolValue])
NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL *destinationFilePath = ...
NSURL *seedFilePath = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:kCoreDataStoreName ofType:nil]];
NSError* err = nil;
if (![fileManager copyItemAtURL:seedPath toURL:destinationFilePath error:&err]) {
NSLog(#"Could not copy seed data. error: %#", err);
// Deal with error
} else {
// Set user defaults kInitialSetupCompleted to YES
}
}
I am looking for a way to programmatically access movies in my documents or movies directory of my iPad, rather than bundling them into the Resources directory. I am programming an iPad application that is heavily dependent on movies, and is intended to be an inhouse demo tool (it will be distributed to only a few iPads in the company). With the movies bundled in to the app, it's almost a full Gig in size. I can't find any way to automatically load a file without placing it in the Resources directory:
NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:#"m4v"];
MPMoviePlayerViewController *thisplayer = [[MPMoviePlayerViewController alloc]
initWithContentURL:[NSURL fileURLWithPath:path]];
[self presentMoviePlayerViewControllerAnimated:thisplayer];
Am I missing something, or is there a security-driven limitation that won't allow me to use the movies directory? Much apologies if I have brainfarted.
You can use the ALAssetsLibrary class to get programmatic access to the movies stored on the user's device. (Alternatively, you can use a media picker to let the user choose which asset to use; then you'll be given a URL which you can load the movie from.)