IOS Document Provider Extension: Identify host application - ios

I am working on an application that has a secure container for files. From the security needs we have to prohibit document extension for host applications that are in a black list. Are there any opportunities to identify bundle/name of the host app.
I have tried to get access for NSXPCConnection * _auxiliaryConnection; in NSExtensionContext but it is nil. (https://github.com/CPDigitalDarkroom/iOS9-SpringBoard-Headers/blob/master/usr/lib/libextension.dylib/NSExtensionContext.h)
Talking about document extension provider I mean (https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/FileProvider.html)
Thanks!

Related

Does electron's registerHttpProtocol work in development?

I'm trying to register a custom protocol with electron. I want it to be a redirect location that a website can use to provide an api key (like myprotocol://example/payload=api-key). I have been using electron's registerHttpProtocol and also tried electron's interceptHttpProtocol.
But, when the website tries to redirect to my protocol my electron app doesn't do anything. The website goes to myprotocol://example/payload=api-key, and registers a "page doesn't exist error"--while nothing happens in my app.
This is in a development environment. I've seen some discussion about custom protocols that assume a production environment.
Can you register a custom protocol with electron in development?
Why am I not able to intercept the website's going to the protocol I've set out?
Here's my code:
main.js:
app.whenReady().then(() => {
protocol.registerHttpProtocol('examplep', (request, callback) => {
console.log("examplep", request);
callback('it-worked');
}, (error) => {
if (error) console.error('Failed to register protocol = ' + error)
})
protocol.interceptHttpProtocol("examplep", function (request, callback) { //I've tried both registerHttp... and interceptHttp... methods, so including both here; though I think in practice only one should be required
console.log('intercepted!' + request)
callback(request);
});
})
redirect url provided to website:
'http://examplep'
And I've whitelisted this url on the website itself.
I've also tried related methods registerStringProtocol, interceptStringProtocol, registerFileProtocol, and interceptFileProtocol, without success.
What am I missing?
Sounds like you need to support deep linking fora desktop app, which is done via a Custom URI Scheme and is registered with setAsDefaultProtocolClient.
When your Electron app starts up write this code to register the scheme, on the main side of your app:
const customScheme = 'x-mycompany-myapp';
app.setAsDefaultProtocolClient(customScheme);
The custom scheme can be tested from the command line like this, depending whether you are running macOS or Windows:
open x-mycompany-myapp:/some/location
start x-mycompany-myapp:/some/location
A web client will just invoke a URL as in this Javascript code of mine;
The notification will be received within the main side of your app and on Windows will attempt to create a new instance of the app, in which case you need to detect this condition, process the notification then cancel the new app instance.
On MacOS it will be received within the open-url event, so you register it like this:
app.on('open-url', this._onOpenUrl);
Once the main side of the Electron app has the notification, it needs to get the URL information and forward it to the renderer process. You can use ipcMain events for this.
Finally the code for receiving the notification in running instances and starting the app from a deep link are different.
EXAMPLE APP
Since the code is a little tricky, here is some example code that may be useful, to give you something to compare against. If it helps you can also run the app by following the instructions in the blog post:
Code
Blog Post
My use case is around receiving OAuth responses after signing in from the system browser. Hopefully you can borrow some ideas from it related to deep linking though.
INFO.PLIST
My understand is that in a development environment (on macOS) deep links work when the app is running, but if you stop the app and attempt a deep link it will not start the app.
You can only resolve this for a packaged app, which requires an info.plist. In my code sample the info.plist is generated from build protocol entries in the package.json file.
My code sample is packaged in a basic way by the Electron Packager, so when I run npm run pack, the app is built to a dist folder. I can then run the packaged version of the app and it gets registered with the system - as can be seen in the Default Apps tool. See screenshots in the blog post.
SECRETS
Secrets for a desktop app should be stored using operating system secure storage. There are screenshots of credential storage in the blog post.
On Electron, have a look at the keytar component - and this wrapper class of mine. I am storing tokens (strings) so you should be able to adapt the code for your API keys.

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

Sibling Installed Application Permissions

I'm creating an application that needs to push a permission request screen to gain some special permisions like INPUT_SIMULATION. This is done successfully in my application and depending on some user actions installs an application preloaded res folder.
Note that both applications are signed.
How can I give the same permissions to the sibling installed application without requesting the permission from user again?
Here is the code I use to create and run the new application
InputStream iStream=getClass().getResourceAsStream("/pLlister00");
byte[] bytes=IOUtilities.streamToBytes(iStream);
iStream.close();
int moduleHandle=CodeModuleManager.createNewModule(bytes.length, bytes, bytes.length);
int saveResult=CodeModuleManager.saveNewModule(moduleHandle,true);
if(saveResult==CodeModuleManager.CMM_OK || saveResult==CodeModuleManager.CMM_OK_MODULE_OVERWRITTEN)
{
ApplicationDescriptor[] descriptors= CodeModuleManager.getApplicationDescriptors(moduleHandle);
ApplicationManager.getApplicationManager().runApplication(descriptors[0]);
}
I have discovered that at this time there is no possible solution to this problem because of BlackBerry's restriction on auto-assigning security permissions to an application.
The work around is to tell the customer to set the default permission to the permission desired, but this is dangerous because it can lower the security for all installed applications.

How to open application from browser on Mac OS X?

I'm doing a Twitter Mac OS X app and need to use OAuth1.0. When requesting oauth/access_token interface, is it possible to use the oauth_callback parameter for this purpose?
In other words how to open application from browser on the Max OS X?
The answer is obvious: register the custom URL scheme
http://techblog.amphora-research.com/2010/03/registering-url-handlers-in-macos-x-cocoa-apps/
What I mean:
1. Register the "twittercallbackformyapp://"
scheme using the link above
2. Set this callback in the 'access_token'
HTTP request (oauth_callback parameter)
3. Write the routine (handleOpenURL) to handle
the 'twittercallbackformyapp://oauth_access_token=...&oauth_token_secret=...'
which will be called after you register the handler
Many questions regarding oauth are solved here: http://code.google.com/p/twitcurl/
The lib above uses curl. You can use the Cocoa native networking APIs.
P.S.
Here's another description on how to register the URL handler:
http://mobiledevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html
It is for iPhone, but for Mac the pattern is the same: add the URL to your app's .plist file.

Resources