diff --git a/packages/share_plus/share_plus/CHANGELOG.md b/packages/share_plus/share_plus/CHANGELOG.md index fdff16097f..47ce4534d2 100644 --- a/packages/share_plus/share_plus/CHANGELOG.md +++ b/packages/share_plus/share_plus/CHANGELOG.md @@ -1,3 +1,7 @@ +## 4.3.0 + +- iOS: Throw PlatformException when iPad share dialog not appearing (sharePositionOrigin not in sourceView) + # 4.2.0 - iOS: Fix Instagram does not show up in provider list for web links diff --git a/packages/share_plus/share_plus/ios/Classes/FLTSharePlusPlugin.m b/packages/share_plus/share_plus/ios/Classes/FLTSharePlusPlugin.m index 450e504c0a..abf29cfaa1 100644 --- a/packages/share_plus/share_plus/ios/Classes/FLTSharePlusPlugin.m +++ b/packages/share_plus/share_plus/ios/Classes/FLTSharePlusPlugin.m @@ -298,11 +298,13 @@ + (void)registerWithRegistrar:(NSObject *)registrar { UIViewController *topViewController = TopViewControllerForViewController(RootViewController()); + [self shareText:shareText subject:shareSubject withController:topViewController atSource:originRect - toResult:withResult ? result : nil]; + toResult:result + withResult:withResult]; if (!withResult) result(nil); } else if ([@"shareFiles" isEqualToString:call.method] || @@ -336,7 +338,8 @@ + (void)registerWithRegistrar:(NSObject *)registrar { withText:text withController:topViewController atSource:originRect - toResult:withResult ? result : nil]; + toResult:result + withResult:withResult]; if (!withResult) result(nil); } else { @@ -349,7 +352,8 @@ + (void)share:(NSArray *)shareItems withSubject:(NSString *)subject withController:(UIViewController *)controller atSource:(CGRect)origin - toResult:(FlutterResult)result { + toResult:(FlutterResult)result + withResult:(BOOL)withResult { UIActivityViewSuccessController *activityViewController = [[UIActivityViewSuccessController alloc] initWithActivityItems:shareItems applicationActivities:nil]; @@ -361,10 +365,32 @@ + (void)share:(NSArray *)shareItems activityViewController.popoverPresentationController.sourceView = controller.view; + BOOL isCoordinateSpaceOfSourceView = + CGRectContainsRect(controller.view.frame, origin); + + // If device is e.g. an iPad then hasPopoverPresentationController is true + BOOL hasPopoverPresentationController = + [activityViewController popoverPresentationController] != NULL; + if (hasPopoverPresentationController && + (!isCoordinateSpaceOfSourceView || CGRectIsEmpty(origin))) { + NSString *sharePositionIssue = [NSString + stringWithFormat: + @"sharePositionOrigin: argument must be set, %@ must be non-zero " + @"and within coordinate space of source view: %@", + NSStringFromCGRect(origin), + NSStringFromCGRect(controller.view.bounds)]; + + result([FlutterError errorWithCode:@"error" + message:sharePositionIssue + details:nil]); + return; + } + if (!CGRectIsEmpty(origin)) { activityViewController.popoverPresentationController.sourceRect = origin; } - if (result) { + + if (withResult) { UIActivityViewSuccessCompanion *companion = [[UIActivityViewSuccessCompanion alloc] initWithResult:result]; activityViewController.companion = companion; @@ -384,7 +410,8 @@ + (void)shareText:(NSString *)shareText subject:(NSString *)subject withController:(UIViewController *)controller atSource:(CGRect)origin - toResult:(FlutterResult)result { + toResult:(FlutterResult)result + withResult:(BOOL)withResult { NSURL *url = [NSURL URLWithString:shareText]; if (!url || ![url scheme] || ![url host]) { NSObject *data = [[SharePlusData alloc] initWithSubject:subject @@ -393,7 +420,8 @@ + (void)shareText:(NSString *)shareText withSubject:subject withController:controller atSource:origin - toResult:result]; + toResult:result + withResult:withResult]; return; } @@ -415,7 +443,8 @@ + (void)shareText:(NSString *)shareText withSubject:subject withController:controller atSource:origin - toResult:result]; + toResult:result + withResult:withResult]; }); return; @@ -430,7 +459,8 @@ + (void)shareText:(NSString *)shareText withSubject:subject withController:controller atSource:origin - toResult:result]; + toResult:result + withResult:withResult]; }); }]; } else { @@ -439,7 +469,8 @@ + (void)shareText:(NSString *)shareText withSubject:subject withController:controller atSource:origin - toResult:result]; + toResult:result + withResult:withResult]; return; } } @@ -450,7 +481,8 @@ + (void)shareFiles:(NSArray *)paths withText:(NSString *)text withController:(UIViewController *)controller atSource:(CGRect)origin - toResult:(FlutterResult)result { + toResult:(FlutterResult)result + withResult:(BOOL)withResult { NSMutableArray *items = [[NSMutableArray alloc] init]; for (int i = 0; i < [paths count]; i++) { @@ -469,7 +501,8 @@ + (void)shareFiles:(NSArray *)paths withSubject:subject withController:controller atSource:origin - toResult:result]; + toResult:result + withResult:withResult]; } @end diff --git a/packages/share_plus/share_plus/pubspec.yaml b/packages/share_plus/share_plus/pubspec.yaml index 0cf136f028..a51d6ac78a 100644 --- a/packages/share_plus/share_plus/pubspec.yaml +++ b/packages/share_plus/share_plus/pubspec.yaml @@ -1,6 +1,6 @@ name: share_plus description: Flutter plugin for sharing content via the platform share UI, using the ACTION_SEND intent on Android and UIActivityViewController on iOS. -version: 4.2.0 +version: 4.3.0 homepage: https://plus.fluttercommunity.dev/ repository: https://github.com/fluttercommunity/plus_plugins/tree/main/packages/ issue_tracker: https://github.com/fluttercommunity/plus_plugins/labels/share_plus