willBeginSendingToApplication not called when open EverNote or any other extention - ios

I have a feature to open docs in other apps from iPhone and iPad app.
Also a flag is set whether to allow this action or not. Few apps can be white listed.
When any app is chosen to open doc
- (void)documentInteractionController:(UIDocumentInteractionController *)controller willBeginSendingToApplication:(NSString *)application
is called.
In this method I can check whether to allow for chosen app or not.
Issue is for Note, Evernote we get two options 1- its extension 2- Open in.
Above method is called for 2 option.
But extensions are launched directly.
I din't found any other delegate method called for this.

Hopefully you figured something out, but my org faced a similar issue and the MDMs we work with don't have an easy solution. We've decided on the following approach.
Always use UIDocumentInteractionController instead of UIActivityViewController
Whenever UIDocumentInteractionController is opened reinit and set the URL to dummy content
Conform to UIDocumentInteractionControllerDelegate and check the application parameter in willBeginSendingToApplication against your whitelist
If application is part of the whitelist then change the value of controller.url to the correct content
The downsides of this approach are that only open-in will work (extensions will always get dummy content) and the user experience isn't great. But if you're building an enterprise app and must prevent data leakage then this is probably the safest way to go.
You can also check out this article for private APIs to hide third-party apps and extensions, mostly in UIActivityViewController:
How to exclude Notes and Reminders apps from the UIActivityViewController?
Unfortunately the way this works seems to have changed between iOS 8 and 9, and again with 10, so it's not optimal. I recommend passing dummy content.

Related

Siri Shortcuts: How do I create a UI for the intent parameters of an iOS shortcut?

I'm trying to create an INIntent to be set up with the new iOS Shortcuts app in iOS 12. I have read the documentation and watched the apple video about it.
I have managed to set everything up and the shortcuts work well, however I can’t seem to figure out how to make customizable options that the user can edit when setting up the shortcut. An example of this would be how the Calendar app’s shortcuts are set up:
Notice the options for Get, Add Filter, Sort by, etc..
I know I can add parameters to the intents in the Intents.intentdefeniton file, but those parameters needs to be set from the app itself before the interaction is donated to the iOS system via SiriKit.
Regardless of what I do the Intent just shows up empty without options.
Any help is appreciated!
I am sorry to bring you bad news, but there is no way to do that. The apps that appear there (like Trello, Overcast, Pocket, etc...) were already supported by Workflow.app before Shortcuts.app was released.
You can try to work around it by calling URL Schemes directly but it might not be the solution you are after.
I think you need to create an Intents UI Extension for this.
https://developer.apple.com/documentation/sirikit/creating_an_intents_ui_extension

How can I share Safari URL to my Cordova/PhoneGap App (ios)?

I am searching for the last week over many websites, and I can see people with the same question, but they are mostly misundestood.
What I have:
I have an iOS application that can receive URL from browsers (made with ionic/cordova)
What I want:
When I am on Safari (or other browser), i want to use the button Share, and my app appear there, in the list, just like Twitter, Facebook, etc. (I put an arrow in the image below).
Like this:
And, I want this working on many iOS versions.
So, I tried to change my app-info.plist many times and nothing works.
Somebody have a solution for this? Somebody have a info.plist that do this job?
(PS: I don´t want to use URL scheme, links, etc... Its the browser SHARE)
Thanks!
The only way is to create a share extension, as mentioned. It is not a trivial task in that you have to incorporate a lot of pieces together to make it work. Also, it is only supported on iOS 8+, which I guess shouldn't be a major issue at present.
In a nutshell:
Create Share Extension in XCode
Create a JS preprocessor
Add plist key/value pairs for related ExtensionAttributes
Set up custom URL scheme
Customize ShareViewController
Set up global handler function to perform your desired actions in app
See Cordova: sharing browser URL to my iOS app (Clipper ios share extension)
Or https://www.inshikos.com/blogs/76/dev/link-and-photo-sharing-to-a-cordova-ios-app-via-share-extensions-ios-8 that expands it further to include photo and wider share scenarios.
And, yes, a terribly misunderstood question with many false positive answers in other posts.

iOS Show UIAlert in Safari when using My App's Share Extension

I'm developing a simple content blocker for iOS 9+ devices. Everything seems to be working fine in terms of blocking ad's / trackers etc and I even have the ability to 'whitelist' websites directly from Safari using a Share Extension Action.
My question is when the user taps Action > My Apps Share Extension [which adds it to a list inside the main app] I want to show a simple Alert that says something like 'This site has been added to your whitelist..." for a few seconds and then disappear.
... how do I do this?
**UPDATE I have read all of Apples documentation on this but still can't figure it out. The post here does actually refer to how to design a streamlined UI but doesn't really cover my situation.
Hoping someone will know :-)
Why you don't use Notifications for this , you can have your notification style set to show like an UIAlert. You can see something like that in Calendar app in iOS.
UPDATE:
I did a little bit more digging , it's not possible to change the style programmatically according to this. So the best choice is handling it when your app is in foreground. I can't think of any other OS wide solution other than local notifications.

ios: Let people share link/image/text TO my app

How can I make my app to appear in Share activity list of Safari, photos, etc.?
I would like to let people share link/image or text through my app like they do on facebook.
Facebook/Twitter etc. are available in default UIActivityType list, but how do other apps like Pinterest, Zomato, etc. acheive this?
The easiest possibility is to use file type association. There are already many tutorials out there, as the concept is already quite established, so I'll just walk you through the main keywords here.
The first thing to determine are the Uniform Type Identifiers (UTI) you want to support. Here is a list of the currently available UTIs from Apple.
Then, in your Xcode project open up the target, and go to the Info tab. There you will find the Document Types entry.
Open it up, and hit the plus sign to add a new document type. Specify a name and the UTI you want to support (in this example I picked PDF):
Note that you also need to supply additional document properties. Most tutorials put in (LSHandlerRank, Alternate) as key, value pair, but I did not find any reason for this. It seems to work with (foo, bar) as well.
Next, run your app to make it register on the device.
When you now have a PDF, say an attachment in your Mail app, your app will now appear on the list:
Finally, in your AppDelegate you need to implement the following method:
-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
NSLog(#"App opened with url %#", url);
return YES;
}
which is called whenever your app received a PDF. The files will go into a special folder called 'Inbox', and the url will tell you the name of the file that has been supplied.
EDIT
This is a sample console output from my iPhone:
2015-03-19 15:27:32.841 so 29147257[3951:1529409] App opened with url file:///private/var/mobile/Containers/Data/Application/A5723926-F869-49C0-A2AF-756795932B81/Documents/Inbox/first-1.pdf
This is new functionality implemented in iOS 8 and up (and OS X 10.10 and up). It's called Extensions. Extensions lets apps leave their Apple sandbox and access other parts of the OS, including notification center and share sheets. Apple puts it like this:
Starting in iOS 8.0 and OS X v10.10, an app extension lets you extend
custom functionality and content beyond your app and make it available
to users while they’re using other apps or the system. You create an
app extension to enable a specific task; after users get your
extension, they can use it to perform that task in a variety of
contexts. For example, if you provide an extension that enables
sharing to your social sharing website, users can use it to post a
remark while surfing the web. Or if you provide an extension that
displays current sports scores, users can put it in Notification
Center so that they can get the latest scores when they open the Today
view. You can even create an extension that provides a custom keyboard
that users can use in place of the iOS system keyboard.
There are several different types of extensions, including Apple Watch apps. You can view all those types in the Apple documentation.
To get started building extensions, here are some resources:
https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/ExtensionCreation.html#//apple_ref/doc/uid/TP40014214-CH5-SW1
http://code.tutsplus.com/tutorials/ios-8-how-to-build-a-simple-action-extension--cms-22794
You will need to use UTImportedTypeDeclarations in info.plist
A good tutorial of this http://www.raywenderlich.com/1948/how-integrate-itunes-file-sharing-with-your-ios-app

"Open in" feature in UIActivityViewController

I need your help with UIActivityViewController.
I need to present activity controller for the file where, except for default actions, the user will be able to open the file in other apps.
I know how to do this with UIDocumentController, which shows popover with all apps able to open the file.
But how can I show all these apps in UIActivityViewController?
P.S. This behavior can be seen in Apple Mail app, for example.
Look at TTOpenInAppActivity for a way to combine both a UIActivityViewController (for normal sharing), and an 'Open in' button on that which brings up a UIDocumentInteractionController. Pre-iOS 8, that is the best way to manage this.
The function and behavior is different between UIActivityViewController and UIDocumentController.
UIActivityViewController
Presents activities that are pre-defined, you can pass an array to select which ones should be excluded among the default ones that are presented, if you want to add more activities you have to use custom activities, unfortunately these will appear bellow the rest of the activities and even more, the icon will always be gray, your app never loses control since you can use delegates and other stuff to know what is going on on those apps. (Unless you manually make an activity which opens another app)
UIDocumentController
This one asks the system for all the registered applications for a certain file extension, many apps have registered their exclusive extensions which makes it so that this app will be the only one displayed. If you pass an image, you will see all the apps that can handle this file. When using this one your app will lose control since the other app will be opened.
What is your final objective?, If you describe it with more detail we could offer you a better solution.
From what i understand, you should see yourself what type of file the user is trying to open, and then yourself open it with the most suitable one.
Since you cant really emulate what apple is doing, you should handle this problem through your interface, offer the user to "share" or to "open with" for example.
The answer is very simple. There is no way to do it. You cannot add the apps except the defaults into the UIActivityViewControllers.
You are absolutley correct, you can acheive this through the UIDocumentInteractionController.

Resources