react-native-share 12.2.4 → 12.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ios/InstagramShare.m +16 -15
- package/ios/WhatsAppShare.m +67 -2
- package/package.json +1 -1
package/ios/InstagramShare.m
CHANGED
|
@@ -127,25 +127,26 @@
|
|
|
127
127
|
_mChangeRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:image];
|
|
128
128
|
placeholder = _mChangeRequest.placeholderForCreatedAsset;
|
|
129
129
|
} completionHandler:^(BOOL success, NSError *error) {
|
|
130
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
131
|
+
if (success) {
|
|
132
|
+
NSURL *instagramURL = [NSURL URLWithString:[NSString stringWithFormat:@"instagram://library?LocalIdentifier=\%@", [placeholder localIdentifier]]];
|
|
130
133
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
if (resolve != NULL) {
|
|
139
|
-
resolve(@[@true, @""]);
|
|
134
|
+
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
|
|
135
|
+
if (@available(iOS 10.0, *)) {
|
|
136
|
+
[[UIApplication sharedApplication] openURL:instagramURL options:@{} completionHandler:NULL];
|
|
137
|
+
}
|
|
138
|
+
if (resolve != NULL) {
|
|
139
|
+
resolve(@[@true, @""]);
|
|
140
|
+
}
|
|
140
141
|
}
|
|
141
142
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
143
|
+
else {
|
|
144
|
+
//Error while writing
|
|
145
|
+
if (reject != NULL) {
|
|
146
|
+
reject(@"com.rnshare",@"error",error);
|
|
147
|
+
}
|
|
147
148
|
}
|
|
148
|
-
}
|
|
149
|
+
});
|
|
149
150
|
}];
|
|
150
151
|
}
|
|
151
152
|
|
package/ios/WhatsAppShare.m
CHANGED
|
@@ -113,7 +113,9 @@ resolve:(RCTPromiseResolveBlock)resolve {
|
|
|
113
113
|
reject:(RCTPromiseRejectBlock)reject {
|
|
114
114
|
|
|
115
115
|
NSString *text = [RCTConvert NSString:options[@"message"]];
|
|
116
|
-
|
|
116
|
+
if (options[@"url"] && options[@"url"] != [NSNull null]) {
|
|
117
|
+
text = [text stringByAppendingString: [@" " stringByAppendingString: options[@"url"]] ];
|
|
118
|
+
}
|
|
117
119
|
NSString *whatsAppNumber = [RCTConvert NSString:options[@"whatsAppNumber"]];
|
|
118
120
|
|
|
119
121
|
text = (NSString*)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL,(CFStringRef) text, NULL,CFSTR("!*'();:@&=+$,/?%#[]"),kCFStringEncodingUTF8));
|
|
@@ -129,6 +131,16 @@ resolve:(RCTPromiseResolveBlock)resolve {
|
|
|
129
131
|
|
|
130
132
|
|
|
131
133
|
-(MessageType)getMessageType: (NSString *)url {
|
|
134
|
+
if (!url || url.length == 0) {
|
|
135
|
+
return MessageTypeText;
|
|
136
|
+
}
|
|
137
|
+
NSURL *parsed = [NSURL URLWithString:url];
|
|
138
|
+
NSString *scheme = parsed.scheme.lowercaseString;
|
|
139
|
+
BOOL isFileOrData = scheme && ([scheme isEqualToString:@"file"] || [scheme isEqualToString:@"data"]);
|
|
140
|
+
BOOL isAbsolutePath = [url hasPrefix:@"/"];
|
|
141
|
+
if (!isFileOrData && !isAbsolutePath) {
|
|
142
|
+
return MessageTypeText;
|
|
143
|
+
}
|
|
132
144
|
NSArray *imageExtensions = @[@"png", @"jpeg",@"jpg",@"gif"];
|
|
133
145
|
if([self isMediaType:url mediaExtensions: imageExtensions]){
|
|
134
146
|
return MessageTypeImage;
|
|
@@ -185,12 +197,65 @@ resolve:(RCTPromiseResolveBlock)resolve {
|
|
|
185
197
|
return FALSE;
|
|
186
198
|
}
|
|
187
199
|
|
|
200
|
+
-(UIView *)presentationView {
|
|
201
|
+
UIWindow *window = nil;
|
|
202
|
+
|
|
203
|
+
if (@available(iOS 13.0, *)) {
|
|
204
|
+
for (UIScene *scene in UIApplication.sharedApplication.connectedScenes) {
|
|
205
|
+
if (![scene isKindOfClass:[UIWindowScene class]]) {
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
UIWindowScene *windowScene = (UIWindowScene *)scene;
|
|
209
|
+
if (windowScene.activationState != UISceneActivationStateForegroundActive) {
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
for (UIWindow *candidate in windowScene.windows) {
|
|
213
|
+
if (candidate.isKeyWindow) {
|
|
214
|
+
window = candidate;
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (window != nil) {
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if (window == nil) {
|
|
225
|
+
for (UIWindow *candidate in UIApplication.sharedApplication.windows) {
|
|
226
|
+
if (candidate.isKeyWindow) {
|
|
227
|
+
window = candidate;
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (window == nil) {
|
|
234
|
+
window = UIApplication.sharedApplication.windows.firstObject;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
UIViewController *viewController = window.rootViewController;
|
|
238
|
+
if (viewController == nil) {
|
|
239
|
+
return nil;
|
|
240
|
+
}
|
|
241
|
+
while (viewController.presentedViewController != nil) {
|
|
242
|
+
viewController = viewController.presentedViewController;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return viewController.view;
|
|
246
|
+
}
|
|
247
|
+
|
|
188
248
|
-(void)shareMedia:(NSString *)stringURL documentUTI:(NSString *)documentUTI {
|
|
189
249
|
NSURL *filePath = [NSURL fileURLWithPath:stringURL];
|
|
190
250
|
documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:filePath];
|
|
191
251
|
documentInteractionController.UTI = documentUTI;
|
|
192
252
|
documentInteractionController.delegate = self;
|
|
193
|
-
|
|
253
|
+
UIView *view = [self presentationView];
|
|
254
|
+
if (view == nil) {
|
|
255
|
+
NSLog(@"Unable to find a presentation view for WhatsApp share");
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
[documentInteractionController presentOpenInMenuFromRect:view.bounds inView:view animated:YES];
|
|
194
259
|
}
|
|
195
260
|
|
|
196
261
|
@end
|
package/package.json
CHANGED