Skip to content

Commit 1453efc

Browse files
neoknNeo Kusanagi
and
Neo Kusanagi
authored
[share_plus] Fix Instagram does not show up in provider list for web links (#1079)
* Fix Instagram does not show up in provider list for web links * update changelog and pubspec.yaml * fix code format * fix format Co-authored-by: Neo Kusanagi <[email protected]>
1 parent e171f5b commit 1453efc

File tree

3 files changed

+102
-8
lines changed

3 files changed

+102
-8
lines changed

packages/share_plus/share_plus/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# 4.2.0
2+
3+
- iOS: Fix Instagram does not show up in provider list for web links
4+
- issue #459 appear again
5+
- put back NSURL for the shareText, when text is pure URL
6+
- using LPMetadataProvider to get LPLinkMetadata make the user experience better
7+
18
## 4.1.0
29

310
- iOS: Fix text sharing.

packages/share_plus/share_plus/ios/Classes/FLTSharePlusPlugin.m

Lines changed: 94 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,18 @@ @interface SharePlusData : NSObject <UIActivityItemSource>
7373
@property(readonly, nonatomic, copy) NSString *text;
7474
@property(readonly, nonatomic, copy) NSString *path;
7575
@property(readonly, nonatomic, copy) NSString *mimeType;
76+
@property(readonly, nonatomic, copy) LPLinkMetadata *linkMetadata;
77+
@property(readonly, nonatomic, copy) NSURL *url;
7678

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

82+
- (instancetype)initWithSubject:(NSString *)subject
83+
url:(NSURL *)url NS_DESIGNATED_INITIALIZER;
84+
85+
- (instancetype)initWithLinkMetadata:(LPLinkMetadata *)metadata
86+
NS_DESIGNATED_INITIALIZER;
87+
8088
- (instancetype)initWithFile:(NSString *)path
8189
mimeType:(NSString *)mimeType NS_DESIGNATED_INITIALIZER;
8290

@@ -105,6 +113,23 @@ - (instancetype)initWithSubject:(NSString *)subject text:(NSString *)text {
105113
return self;
106114
}
107115

116+
- (instancetype)initWithSubject:(NSString *)subject url:(NSURL *)url {
117+
self = [super init];
118+
if (self) {
119+
_subject = [subject isKindOfClass:NSNull.class] ? @"" : subject;
120+
_url = url;
121+
}
122+
return self;
123+
}
124+
125+
- (instancetype)initWithLinkMetadata:(LPLinkMetadata *)metadata {
126+
self = [super init];
127+
if (self) {
128+
_linkMetadata = metadata;
129+
}
130+
return self;
131+
}
132+
108133
- (instancetype)initWithFile:(NSString *)path mimeType:(NSString *)mimeType {
109134
self = [super init];
110135
if (self) {
@@ -135,6 +160,14 @@ - (id)activityViewControllerPlaceholderItem:
135160

136161
- (id)activityViewController:(UIActivityViewController *)activityViewController
137162
itemForActivityType:(UIActivityType)activityType {
163+
if (_linkMetadata != nil) {
164+
return _linkMetadata.originalURL;
165+
}
166+
167+
if (_url != nil) {
168+
return _url;
169+
}
170+
138171
if (!_path || !_mimeType) {
139172
return _text;
140173
}
@@ -182,6 +215,10 @@ - (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize {
182215
- (LPLinkMetadata *)activityViewControllerLinkMetadata:
183216
(UIActivityViewController *)activityViewController
184217
API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0)) {
218+
if (_linkMetadata != nil) {
219+
return _linkMetadata;
220+
}
221+
185222
LPLinkMetadata *metadata = [[LPLinkMetadata alloc] init];
186223

187224
if ([_subject length] > 0) {
@@ -348,13 +385,63 @@ + (void)shareText:(NSString *)shareText
348385
withController:(UIViewController *)controller
349386
atSource:(CGRect)origin
350387
toResult:(FlutterResult)result {
351-
NSObject *data = [[SharePlusData alloc] initWithSubject:subject
352-
text:shareText];
353-
[self share:@[ data ]
354-
withSubject:subject
355-
withController:controller
356-
atSource:origin
357-
toResult:result];
388+
NSURL *url = [NSURL URLWithString:shareText];
389+
if (!url || ![url scheme] || ![url host]) {
390+
NSObject *data = [[SharePlusData alloc] initWithSubject:subject
391+
text:shareText];
392+
[self share:@[ data ]
393+
withSubject:subject
394+
withController:controller
395+
atSource:origin
396+
toResult:result];
397+
return;
398+
}
399+
400+
if (@available(iOS 13, *) && ([[url scheme] isEqualToString:@"http"] ||
401+
[[url scheme] isEqualToString:@"https"])) {
402+
LPMetadataProvider *metadataProvider = [[LPMetadataProvider alloc] init];
403+
[metadataProvider
404+
startFetchingMetadataForURL:url
405+
completionHandler:^(LPLinkMetadata *metadata,
406+
NSError *error) {
407+
if (!error) {
408+
if (subject != nil && [subject length] > 0) {
409+
metadata.title = subject;
410+
}
411+
NSObject *data =
412+
[[SharePlusData alloc] initWithLinkMetadata:metadata];
413+
dispatch_async(dispatch_get_main_queue(), ^{
414+
[self share:@[ data ]
415+
withSubject:subject
416+
withController:controller
417+
atSource:origin
418+
toResult:result];
419+
});
420+
421+
return;
422+
}
423+
424+
NSLog(@"FetchingMetadataForURL %@ got error: %@", url,
425+
error);
426+
NSObject *data =
427+
[[SharePlusData alloc] initWithSubject:subject url:url];
428+
dispatch_async(dispatch_get_main_queue(), ^{
429+
[self share:@[ data ]
430+
withSubject:subject
431+
withController:controller
432+
atSource:origin
433+
toResult:result];
434+
});
435+
}];
436+
} else {
437+
NSObject *data = [[SharePlusData alloc] initWithSubject:subject url:url];
438+
[self share:@[ data ]
439+
withSubject:subject
440+
withController:controller
441+
atSource:origin
442+
toResult:result];
443+
return;
444+
}
358445
}
359446

360447
+ (void)shareFiles:(NSArray *)paths

packages/share_plus/share_plus/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: share_plus
22
description: Flutter plugin for sharing content via the platform share UI, using the ACTION_SEND intent on Android and UIActivityViewController on iOS.
3-
version: 4.1.0
3+
version: 4.2.0
44
homepage: https://plus.fluttercommunity.dev/
55
repository: https://github.com/fluttercommunity/plus_plugins/tree/main/packages/
66
issue_tracker: https://github.com/fluttercommunity/plus_plugins/labels/share_plus

0 commit comments

Comments
 (0)