Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/share/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.6.2+3

* Fix iOS crash when setting subject to null.

## 0.6.2+2

* Update and migrate iOS example project.
Expand Down
52 changes: 47 additions & 5 deletions packages/share/ios/Classes/SharePlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,49 @@

static NSString *const PLATFORM_CHANNEL = @"plugins.flutter.io/share";

@interface ShareData : NSObject <UIActivityItemSource>

@property(readonly, nonatomic, copy) NSString *subject;
@property(readonly, nonatomic, copy) NSString *text;

- (instancetype)initWithSubject:(NSString *)subject text:(NSString *)text NS_DESIGNATED_INITIALIZER;

- (instancetype)init __attribute__((unavailable("Use initWithSubject:text: instead")));

@end

@implementation ShareData

- (instancetype)init {
[super doesNotRecognizeSelector:_cmd];
return nil;
}

- (instancetype)initWithSubject:(NSString *)subject text:(NSString *)text {
self = [super init];
if (self) {
_subject = subject;
_text = text;
}
return self;
}

- (id)activityViewControllerPlaceholderItem:(UIActivityViewController *)activityViewController {
return @"";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious - should this be null?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per https://developer.apple.com/documentation/uikit/uiactivityitemsource/1620458-activityviewcontrollerplaceholde?language=objc

It should be one that the activity can handle otherwise you may get an activity with empty content.

So setting it to null/nil will result the activityController showing an empty content (manually tested)

}

- (id)activityViewController:(UIActivityViewController *)activityViewController
itemForActivityType:(UIActivityType)activityType {
return _text;
}

- (NSString *)activityViewController:(UIActivityViewController *)activityViewController
subjectForActivityType:(UIActivityType)activityType {
return [_subject isKindOfClass:NSNull.class] ? nil : _subject;
}

@end

@implementation FLTSharePlugin

+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
Expand All @@ -31,7 +74,7 @@ + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
NSNumber *originWidth = arguments[@"originWidth"];
NSNumber *originHeight = arguments[@"originHeight"];

CGRect originRect;
CGRect originRect = CGRectZero;
if (originX != nil && originY != nil && originWidth != nil && originHeight != nil) {
originRect = CGRectMake([originX doubleValue], [originY doubleValue],
[originWidth doubleValue], [originHeight doubleValue]);
Expand All @@ -48,14 +91,13 @@ + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
}];
}

+ (void)share:(id)sharedItems
+ (void)share:(NSString *)shareText
subject:(NSString *)subject
withController:(UIViewController *)controller
atSource:(CGRect)origin {
ShareData *data = [[ShareData alloc] initWithSubject:subject text:shareText];
UIActivityViewController *activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:@[ sharedItems ]
applicationActivities:nil];
[activityViewController setValue:subject forKey:@"subject"];
[[UIActivityViewController alloc] initWithActivityItems:@[ data ] applicationActivities:nil];
activityViewController.popoverPresentationController.sourceView = controller.view;
if (!CGRectIsEmpty(origin)) {
activityViewController.popoverPresentationController.sourceRect = origin;
Expand Down
2 changes: 1 addition & 1 deletion packages/share/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for sharing content via the platform share UI, using
the ACTION_SEND intent on Android and UIActivityViewController on iOS.
author: Flutter Team <[email protected]>
homepage: https://github.com/flutter/plugins/tree/master/packages/share
version: 0.6.2+2
version: 0.6.2+3

flutter:
plugin:
Expand Down