39
39
return viewController;
40
40
}
41
41
42
+ static NSDictionary *activityTypes;
43
+
44
+ static void initializeActivityTypeMapping (void ) {
45
+ static dispatch_once_t onceToken;
46
+ dispatch_once (&onceToken, ^{
47
+ NSMutableDictionary *originalTypes =
48
+ [[NSMutableDictionary alloc ] initWithDictionary: @{
49
+ @" postToFacebook" : UIActivityTypePostToFacebook,
50
+ @" postToTwitter" : UIActivityTypePostToTwitter,
51
+ @" postToWeibo" : UIActivityTypePostToWeibo,
52
+ @" message" : UIActivityTypeMessage,
53
+ @" mail" : UIActivityTypeMail,
54
+ @" print" : UIActivityTypePrint,
55
+ @" copyToPasteboard" : UIActivityTypeCopyToPasteboard,
56
+ @" assignToContact" : UIActivityTypeAssignToContact,
57
+ @" saveToCameraRoll" : UIActivityTypeSaveToCameraRoll,
58
+ @" addToReadingList" : UIActivityTypeAddToReadingList,
59
+ @" postToFlickr" : UIActivityTypePostToFlickr,
60
+ @" postToVimeo" : UIActivityTypePostToVimeo,
61
+ @" postToTencentWeibo" : UIActivityTypePostToTencentWeibo,
62
+ @" airDrop" : UIActivityTypeAirDrop,
63
+ @" openInIBooks" : UIActivityTypeOpenInIBooks,
64
+ @" markupAsPDF" : UIActivityTypeMarkupAsPDF,
65
+ }];
66
+
67
+ if (@available (iOS 15.4 , *)) {
68
+ originalTypes[@" sharePlay" ] = UIActivityTypeSharePlay;
69
+ }
70
+
71
+ if (@available (iOS 16.0 , *)) {
72
+ originalTypes[@" collaborationInviteWithLink" ] =
73
+ UIActivityTypeCollaborationInviteWithLink;
74
+ }
75
+
76
+ if (@available (iOS 16.0 , *)) {
77
+ originalTypes[@" collaborationCopyLink" ] =
78
+ UIActivityTypeCollaborationCopyLink;
79
+ }
80
+ if (@available (iOS 16.4 , *)) {
81
+ originalTypes[@" addToHomeScreen" ] = UIActivityTypeAddToHomeScreen;
82
+ }
83
+ activityTypes = originalTypes;
84
+ });
85
+ }
86
+
87
+ static UIActivityType activityTypeForString (NSString *activityTypeString) {
88
+ initializeActivityTypeMapping ();
89
+ if ([activityTypes.allKeys containsObject: activityTypeString]) {
90
+ return activityTypes[activityTypeString];
91
+ }
92
+ return nil ;
93
+ }
94
+
42
95
// We need the companion to avoid ARC deadlock
43
96
@interface UIActivityViewSuccessCompanion : NSObject
44
97
@@ -254,7 +307,16 @@ + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
254
307
NSNumber *originY = arguments[@" originY" ];
255
308
NSNumber *originWidth = arguments[@" originWidth" ];
256
309
NSNumber *originHeight = arguments[@" originHeight" ];
257
-
310
+ NSArray *rawExcludedActivityTypes = arguments[@" excludedActivityTypes" ];
311
+ NSMutableArray *excludedActivityTypes = [[NSMutableArray alloc ] init ];
312
+ if (rawExcludedActivityTypes && rawExcludedActivityTypes.count > 0 ) {
313
+ for (NSString *type in rawExcludedActivityTypes) {
314
+ UIActivityType activityType = activityTypeForString (type);
315
+ if (activityType != nil ) {
316
+ [excludedActivityTypes addObject: activityType];
317
+ }
318
+ }
319
+ }
258
320
CGRect originRect = CGRectZero ;
259
321
if (originX && originY && originWidth && originHeight) {
260
322
originRect =
@@ -285,6 +347,7 @@ + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
285
347
286
348
[self shareText: shareText
287
349
subject: shareSubject
350
+ excludedActivityTypes: excludedActivityTypes
288
351
withController: topViewController
289
352
atSource: originRect
290
353
toResult: result];
@@ -323,6 +386,7 @@ + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
323
386
withMimeType: mimeTypes
324
387
withSubject: subject
325
388
withText: text
389
+ excludedActivityTypes: excludedActivityTypes
326
390
withController: topViewController
327
391
atSource: originRect
328
392
toResult: result];
@@ -347,6 +411,7 @@ + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
347
411
TopViewControllerForViewController (rootViewController);
348
412
349
413
[self shareUri: uri
414
+ excludedActivityTypes: excludedActivityTypes
350
415
withController: topViewController
351
416
atSource: originRect
352
417
toResult: result];
@@ -358,6 +423,7 @@ + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
358
423
359
424
+ (void )share : (NSArray *)shareItems
360
425
withSubject : (NSString *)subject
426
+ excludedActivityTypes : (NSMutableArray *)excludedActivityTypes
361
427
withController : (UIViewController *)controller
362
428
atSource : (CGRect )origin
363
429
toResult : (FlutterResult)result {
@@ -369,6 +435,7 @@ + (void)share:(NSArray *)shareItems
369
435
if (![subject isKindOfClass: [NSNull class ]]) {
370
436
[activityViewController setValue: subject forKey: @" subject" ];
371
437
}
438
+ activityViewController.excludedActivityTypes = excludedActivityTypes;
372
439
373
440
activityViewController.popoverPresentationController .sourceView =
374
441
controller.view ;
@@ -413,26 +480,30 @@ + (void)share:(NSArray *)shareItems
413
480
}
414
481
415
482
+ (void )shareUri: (NSString *)uri
483
+ excludedActivityTypes: excludedActivityTypes
416
484
withController: (UIViewController *)controller
417
485
atSource: (CGRect )origin
418
486
toResult: (FlutterResult)result {
419
487
NSURL *data = [NSURL URLWithString: uri];
420
488
[self share: @[ data ]
421
489
withSubject: nil
490
+ excludedActivityTypes: excludedActivityTypes
422
491
withController: controller
423
492
atSource: origin
424
493
toResult: result];
425
494
}
426
495
427
496
+ (void )shareText: (NSString *)shareText
428
497
subject: (NSString *)subject
498
+ excludedActivityTypes: excludedActivityTypes
429
499
withController: (UIViewController *)controller
430
500
atSource: (CGRect )origin
431
501
toResult: (FlutterResult)result {
432
502
NSObject *data = [[SharePlusData alloc ] initWithSubject: subject
433
503
text: shareText];
434
504
[self share: @[ data ]
435
505
withSubject: subject
506
+ excludedActivityTypes: excludedActivityTypes
436
507
withController: controller
437
508
atSource: origin
438
509
toResult: result];
@@ -442,6 +513,7 @@ + (void)shareFiles:(NSArray *)paths
442
513
withMimeType: (NSArray *)mimeTypes
443
514
withSubject: (NSString *)subject
444
515
withText: (NSString *)text
516
+ excludedActivityTypes: (NSMutableArray *)excludedActivityTypes
445
517
withController: (UIViewController *)controller
446
518
atSource: (CGRect )origin
447
519
toResult: (FlutterResult)result {
@@ -461,6 +533,7 @@ + (void)shareFiles:(NSArray *)paths
461
533
462
534
[self share: items
463
535
withSubject: subject
536
+ excludedActivityTypes: excludedActivityTypes
464
537
withController: controller
465
538
atSource: origin
466
539
toResult: result];
0 commit comments