iOS how to access private file for sharing extension - ios

I have been trying to access a file with my share extension, if the file is from photos app, I can access it, the path for the file is:
file:///var/mobile/Media/PhotoData/OutgoingTemp/11485686-0D4A-4637-AA50-B14D83E18B01/RenderedPhoto/IMG_4807.JPG
but when I try to access a file on the "private" path, I cannot access it, like an MS word file:
file:///private/var/mobile/Containers/Data/Application/196D7E75-87B6-4C69-B97A-74E58DF4AD65/tmp/ShareAttachments/%7BE73A233D-D10E-814D-AEB1-0C8C8AC9BFAA%7D/Document%20(7).docx
So my question is, how to access the file? apps like whatsApp or slack can have access to the file and attach it...
How to access this file? are they using "app groups"? how do they get the id for the app group? or how to access the file?

For Share Extension, you need to get the file from NSItemProvider, which is passed by the host app to your share extension.
For a file, it may be a Data type or a URL type. If it is data, you need to cast it to the type you need. If it is a url, you can load it.

Please follow the given link:-
https://developer.apple.com/app-extensions/
Thank you.
Shriram

Related

Is there a way to attach file with outlook's URL scheme?

I'm creating an ios application that opens the outlook app and attaches file. I can open the outlook app via this URL scheme
ms-outlook://compose?to=joe#example.com&subject=Hello&body=Hello but do not know how to attach file. Is there a way to attach the file from the URL scheme? Thank you for your time.
No, there is no way to specify an attachment using a URL scheme or the mailto protocol.

iOS Universal Link With PRIVATE domain

I am trying setup iOS universal link with a private server. I put my apple-app-site-association on my private_domain/apple-app-site-association .
However, iOS can not download the Apple-app-site-association from server even testing device in the same network as my private domain . I am wondering if it possible to set up Universal Link with Private Domain ? Thanks
This is not possible, no. You'll see in the device logs, if you watch during app installation, that setup of universal links is failing because the domain cannot be reached.
You can work around this by creating a public domain (just use an Azure site or something similar). The apple-app-site-association must exist as a static file. Note that if you are using Azure you'll need to add a file handler for the empty file extension and another file handler for Android's json file extension if you're doing Android as well.
If you want the links to work for web as well then just have the paths redirect to your internal (private) domain.

How to open a local file in Office on iOS

I've saved a file locally and want to open it in Word if installed. For example my file's URL is:
file:///var/mobile/Containers/Data/Application/{guid}/Library/Caches/MyFile.docx
My Office URL is:
ms-word:ofe|u|file:///var/mobile/Containers/Data/Application/{guid}/Library/Caches/MyFile.docx|p|my-protocol
When Word launches it says:
The link you clicked on is invalid and the document cannot be opened
However if I feed the original URL to a UIDocumentInteractionController it opens correctly.
Any ideas?
If you pass the URL to Word directly you are attempting to violate your Application Sandbox - Word doesn't have access to your App's directory, so it can't read the file.
You have to use the UIDocumentInteractionController to prompt the user to open the document in Word or you need to store the document somewhere that Word can read it (this would be external to your device - on a cloud store somewhere)

Launching a different app to open file on server

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.

Get path from a file that trigger an app

I´m downloading a file to a SD card in the BlackBerry, and when I open that file, my application run. So when my application run, I need to delete that file.
The problem is that I dont know where it is(the file) from my app, because the user could download that file anywhere.
Is there something in the BB OS that let me know the path of that file? With this I can give to my app a parameter or something...
Well, thats it.
If you register with invocation registry so that your app is invoked whenever file needs to be opened, you will get full URL in Invocation object. This URL is sufficient to delete the file via FileConnector.
See this BlackBerry example to properly register your app. Also, in step 6 note invoc.getURL() - this is what you need to use.

Resources