iOS: open file with UIDocumentInteractionController and know what app opened the file - ios

I'm using presentOpenInMenuFromRect:inView:animated: to open documents in my app. The document interaction controller dismisses the menu automatically when the user selects an appropriate option. You can also dismiss it programmatically using the dismissMenuAnimated: method.
I would like to know the app used to open this document when dismiss the menu.

This method is called when the user chooses to open a document:
documentInteractionController:willBeginSendingToApplication:
on the UIDocumentInteractionControllerDelegate Protocol.
The "application" parameter is the bundle identifier of the application that is about to open the document. This value corresponds to the value in the CFBundleIdentifier key of the application’s Info.plist file.

Related

WARNING ITMS-90737: "Invalid Document Configuration [duplicate]

This question already has answers here:
App Store Connect Warns - Invalid Document Configuration
(7 answers)
Closed 4 years ago.
I got this error message when uploading my app to ItunesConnect today,
Invalid Document Configuration - Document Based Apps should support
either the Document Browser (UISupportsDocumentBrowser = YES) or
implement Open In Place (LSSupportsOpeningDocumentsInPlace = YES/NO).
Visit https://developer.apple.com/document-based-apps/ for more
information.
To Fix -
Open Info.plist file.
If you have UIDocumentInteractionController within your App use -
Add "UISupportsDocumentBrowser" select boolean YES
Otherwise -
Add "LSSupportsOpeningDocumentsInPlace" select boolean YES
Info.plist Code:
//if using - UIDocumentInteractionController
<key>UISupportsDocumentBrowser</key>
<true/>
//if not use -
<key>LSSupportsOpeningDocumentsInPlace</key>
<true/>
From the Apple Developer Documentation
UISupportsDocumentBrowser
UISupportsDocumentBrowser (Boolean - iOS) Specifies that the app is a document-based app and uses the UIDocumentBrowserViewController class.
If this key is set to YES, the user can set the document browser’s default save location in Settings. Additionally, the local file provider grants access to all the documents in the app’s Documents directory. These documents appear in the Files app, and in a Document Browser. Users can open and edit these document in place.
This key is supported in iOS 11 and later.
UIDocumentInteractionController
Use this class to present an appropriate user interface for previewing, opening, copying, or printing a specified file. For example, an email program might use this class to allow the user to preview attachments and open them in other apps.
After presenting its user interface, a document interaction controller handles all interactions needed to support file preview and menu display.
You can also use the delegate to participate in interactions occurring within the presented interface. For example, the delegate is notified when a file is about to be handed off to another application for opening. For a complete description of the methods you can implement in your delegate, see UIDocumentInteractionControllerDelegate.
Reference Link
LSSupportsOpeningDocumentsInPlace
LSSupportsOpeningDocumentsInPlace (Boolean - iOS) When set to a value of YES, enables your app to open the original document from a file provider, rather than a copy of the document. The app can access documents from the system’s local file provider, the iCloud file provider, and any third-party File Provider extensions that support opening documents in place.
The URL for a document opened in place is security-scoped. For information about working with security-scoped URLs and bookmarks, read the overview in NSURL Class Reference and read Document Provider in App Extension Programming Guide.
Important: When opening a document in place, other processes can modify the document at any time. Therefore, you must coordinate your access to the document using either a UIDocument subclass or NSFilePresenter and NSFileCoordinator objects.
In iOS 11 and later, if both this key and the UIFileSharingEnabled key are YES, the local file provider grants access to all the documents in the app’s Documents directory. These documents appear in the Files app, and in a document browser. Users can open and edit these document in place.
Reference Link
Setting Up a Document Browser App Link

iOS App Extensions (Widgets): Open URL, and then execute a method within the app

In an iOS App Extension such as the Today Widget, you can open the application when the widget is selected using NSExtensionContext. Is there any way to execute a method within the application (to move to a different UI view) only after the application is opened via the widget?
You will have to create a custom URL scheme which your app will register for and change the view based on the URL.
Example: myapp://action=showspecialview
Your app would then be launched and can parse the URL and do the special behavior when it detects showspecialview in the URL.

Add "Edit in Excel" or "Edit photo" extension

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).

Open iOS app from browser

What I want to do is,
We have having one product info on Website.
That product is available on store.
what we have on website is that, Product info and one button for that product.
I want to take two actions on that button.
When User opens website on iPad or iPhone on Safari (browser) and click on GetProduct button, then following two actions must be taken place.
1. If user is already having product installed on device then directly open the app in device.
2. If user is not having the app on device then link user to the app on store, so he can download from there.
I already handled second condition,
but how to handle the first condition.
If I am already having the app then how to open it on action of button click in browser.
You can achieve what you're asking for by using a URL scheme. This will enable you to call the openUrl: method with your application's url scheme which will then launch your app.
Here's how you setup a custom url scheme:
Open your app's Info.plist and add a row with a key called URL Types.
Expand the URL Types item, and Item 0 under it and you'll see URL Identifier
Enter your app's bundle identifier (e.g. com.myCompany.myApp) as the URL Identifier value.
Add another row to Item 0 and enter URL Schemes.
Expand the URL Schemes and under Item 0 type in the name for your custom scheme (e.g. myScheme).
You should now be able to open your app from Safari by typing myScheme:// in the address bar.
Alternatively, from your app, you can launch the other app like this:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"myScheme://"]];
Note that you can also send parameters to the app you're launching with the url scheme (more on that here).
With iOS9 Apple introduced a way to open installed app from Links. Here is the official link for this : Apple universal links

URL Schemes-sending action ios

I have devoleped 3 applications,one of them called Main-app and it contains icons of the two others app and a button to access to thew from the main-app.the problem is that if I want to add an app from the app store,how can I get the icon and create a button dynamically into the main-app? I suggest to use URL Schemes between apps but I dont know how to do it.
One way is to have all the app names and icons in each app's bundle and differentiate them using the "sourceApplication" parameter of the application:openURL:sourceApplication:annotation: method of UIApplicationDelegate

Resources