Skip to content

Commit

Permalink
fix: suppress errors occurred when built with ios sdk 12 or lower (#742)
Browse files Browse the repository at this point in the history
  • Loading branch information
miyabi committed Mar 25, 2020
1 parent 39609c4 commit 4f9eaf4
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ios/RNShareActivityItemSource.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#import "RNShareActivityItemSource.h"

#ifdef __IPHONE_13_0
#import <LinkPresentation/LinkPresentation.h>
#endif

// import RCTBridgeModule
#if __has_include(<React/RCTBridgeModule.h>)
Expand All @@ -25,21 +28,25 @@ @implementation RNShareActivityItemSource {
NSDictionary *subjectDictionary;
NSDictionary *dataTypeIdentifierDictionary;
NSDictionary *thumbnailImageDictionary;
#ifdef __IPHONE_13_0
LPLinkMetadata *linkMetadata API_AVAILABLE(ios(13.0));
#endif
}

- (instancetype)initWithOptions:(NSDictionary *)options {
self = [super init];
if (self) {
placeholderItem = [RNShareActivityItemSource itemFromDictionary:options[@"placeholderItem"]];

#ifdef __IPHONE_13_0
if (@available(iOS 13.0, *)) {
linkMetadata = [RNShareActivityItemSource linkMetadataFromDictionary:options[@"linkMetadata"]];
if ([placeholderItem isKindOfClass:NSURL.class] && ![RNShareActivityItemSource isURLSchemeData:placeholderItem]) {
NSURL *URL = placeholderItem;
[self fetchMetadataForURL:URL];
}
}
#endif

itemDictionary = options[@"item"];
subjectDictionary = options[@"subject"];
Expand All @@ -50,6 +57,7 @@ - (instancetype)initWithOptions:(NSDictionary *)options {
}

- (void)fetchMetadataForURL:(nonnull NSURL *)URL {
#ifdef __IPHONE_13_0
if (@available(iOS 13.0, *)) {
LPMetadataProvider *metadataProvider = [[LPMetadataProvider alloc] init];
[metadataProvider startFetchingMetadataForURL:URL completionHandler:^(LPLinkMetadata * _Nullable metadata, NSError * _Nullable error) {
Expand All @@ -70,6 +78,7 @@ - (void)fetchMetadataForURL:(nonnull NSURL *)URL {
}
}];
}
#endif
}

#pragma mark - Utilities
Expand Down Expand Up @@ -103,6 +112,7 @@ + (nullable id)itemFromDictionary:(NSDictionary *)dictionary {
return nil;
}

#ifdef __IPHONE_13_0
+ (nullable LPLinkMetadata *)linkMetadataFromDictionary:(NSDictionary *)dictionary API_AVAILABLE(ios(13.0)) {
if (dictionary) {
LPLinkMetadata *linkMetadata = [[LPLinkMetadata alloc] init];
Expand All @@ -126,6 +136,7 @@ + (nullable LPLinkMetadata *)linkMetadataFromDictionary:(NSDictionary *)dictiona
}
return nil;
}
#endif

+ (nullable NSString *)keyForActivityType:(UIActivityType)activityType {
if ([activityType isEqual:UIActivityTypeAddToReadingList]) {
Expand Down Expand Up @@ -270,8 +281,10 @@ - (UIImage *)activityViewController:(UIActivityViewController *)activityViewCont
return nil;
}

#ifdef __IPHONE_13_0
- (LPLinkMetadata *)activityViewControllerLinkMetadata:(UIActivityViewController *)activityViewController API_AVAILABLE(ios(13.0)) {
return linkMetadata;
}
#endif

@end

0 comments on commit 4f9eaf4

Please sign in to comment.