How to exclude Notes and Reminders apps from the UIActivityViewController?
There is a way, but involves private API.
Sometimes Apple makes exceptions, especially if you fix a bug.
Let's dive into details...
UIActivityViewController has got a private method called "_availableActivitiesForItems:", which returns an array of UISocialActivity objects.
UISocialActivity has got an interesting property, called "activityType", which returns a domain-formatted activity type.
After some tests, I managed to discover the Reminder and Notes activity types:
- com.apple.reminders.RemindersEditorExtension
- com.apple.mobilenotes.SharingExtension
Unfortunately, passing those two types into ".excludedActivityTypes" didn't make any difference.
"_availableActivitiesForItems:" to the rescue!
OLD WAY:
Update: I've found a better way to do it.
The first solution I've posted doesn't work in some cases, thus shouldn't be considered stable.
Header:
#import
@interface UISocialActivity : NSObject
- (id)activityType;
@end
@interface UIActivityViewController (Private)
- (id)_availableActivitiesForItems:(id)arg1;
@end
@interface ActivityViewController : UIActivityViewController
@end
Implementation:
@implementation ActivityViewController
- (id)_availableActivitiesForItems:(id)arg1
{
id activities = [super _availableActivitiesForItems:arg1];
NSMutableArray *filteredActivities = [NSMutableArray array];
[activities enumerateObjectsUsingBlock:^(UISocialActivity* _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if (![[obj activityType] isEqualToString:@"com.apple.reminders.RemindersEditorExtension"] &&
![[obj activityType] isEqualToString:@"com.apple.mobilenotes.SharingExtension"]) {
[filteredActivities addObject:obj];
}
}];
return [NSArray arrayWithArray:filteredActivities];
}
@end
NEW WAY:
Header:
@interface UIActivityViewController (Private)
- (BOOL)_shouldExcludeActivityType:(UIActivity*)activity;
@end
@interface ActivityViewController : UIActivityViewController
@end
Implementation:
@implementation ActivityViewController
- (BOOL)_shouldExcludeActivityType:(UIActivity *)activity
{
if ([[activity activityType] isEqualToString:@"com.apple.reminders.RemindersEditorExtension"] ||
[[activity activityType] isEqualToString:@"com.apple.mobilenotes.SharingExtension"]) {
return YES;
}
return [super _shouldExcludeActivityType:activity];
}
@end
"Illegal", but it works.
It would be great to know if it actually passes Apple validation.
Excluding UIActivities from UIActivityViewController
You cannot exclude apps from UIActivityViewController
, because these apps were declared that they can open and handle .csv file types (via Document types
in Info.plist
).
If you don't want to show these apps, you can share file directly to the destination. For example for email you can use MFMailComposeViewController
.
Related Topics
Swift - Stored Values Order Is Completely Changed in Dictionary
How to Use Uivisualeffectview to Blur Image
How to Share an Image on Instagram in Ios
Move a View Up Only When the Keyboard Covers an Input Field
Check For Internet Connection Availability in Swift
How to Scale Down a Uiimage and Make It Crispy/Sharp At the Same Time Instead of Blurry
Nsurlconnection and Basic Http Authentication in Ios
How to Create Launch Images For Iphone 6/6 Plus Landscape Only Apps
Ios9 Getting Error "An Ssl Error Has Occurred and a Secure Connection to the Server Cannot Be Made"
Correct Singleton Pattern Objective C (Ios)
How to Import Own Classes from Your Own Project into a Playground
Xcode 9 Gm - Wkwebview Nscoding Support Was Broken in Previous Versions
Determine If Mkmapview Was Dragged/Moved