react-native-share 12.0.10 → 12.0.11

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.
@@ -14,9 +14,9 @@
14
14
  - (void)shareSingle:(NSDictionary *)options
15
15
  reject:(RCTPromiseRejectBlock)reject
16
16
  resolve:(RCTPromiseResolveBlock)resolve {
17
-
17
+
18
18
  NSLog(@"Try open view");
19
-
19
+
20
20
  NSURL * shareURL;
21
21
  float videoDurationSeconds = 0.0f;
22
22
  NSString* url = options[@"url"];
@@ -25,13 +25,13 @@
25
25
  AVURLAsset* videoAsset = [AVURLAsset URLAssetWithURL:fileURL options:nil];
26
26
  CMTime videoDuration = videoAsset.duration;
27
27
  float videoDurationSeconds = CMTimeGetSeconds(videoDuration);
28
-
28
+
29
29
  NSLog(@"Video duration: %f seconds for file %@", videoDurationSeconds, videoAsset.URL.absoluteString);
30
30
  } else {
31
31
  //this will send message directly to instagram DM with plain text
32
32
  shareURL = [NSURL URLWithString:[NSString stringWithFormat:@"instagram://sharesheet?text=%@", options[@"message"]]];
33
33
  }
34
-
34
+
35
35
  if (shareURL) {
36
36
  NSLog(@"url is already available, no need to do anything");
37
37
  } else if (videoDurationSeconds <= 60.0f) {
@@ -42,7 +42,7 @@
42
42
  } else {
43
43
  shareURL = [NSURL URLWithString:@"instagram://camera"];
44
44
  }
45
-
45
+
46
46
  if ([[UIApplication sharedApplication] canOpenURL: shareURL]) {
47
47
  [[UIApplication sharedApplication] openURL:shareURL options:@{} completionHandler:nil];
48
48
  resolve(@[@true, @""]);
@@ -50,22 +50,22 @@
50
50
  // Cannot open instagram
51
51
  NSString *stringURL = @"https://itunes.apple.com/app/instagram/id389801252";
52
52
  NSURL *url = [NSURL URLWithString:stringURL];
53
-
53
+
54
54
  [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) {}];
55
-
55
+
56
56
  NSString *errorMessage = @"Not installed";
57
57
  NSDictionary *userInfo = @{NSLocalizedFailureReasonErrorKey: NSLocalizedString(errorMessage, nil)};
58
58
  NSError *error = [NSError errorWithDomain:@"com.rnshare" code:1 userInfo:userInfo];
59
-
59
+
60
60
  NSLog(@"%@", errorMessage);
61
61
  reject(@"com.rnshare",@"Not installed",error);
62
- }
62
+ }
63
63
  }
64
64
 
65
65
  - (void)shareSingleImage:(NSDictionary *)options
66
66
  reject:(RCTPromiseRejectBlock)reject
67
67
  resolve:(RCTPromiseResolveBlock)resolve {
68
-
68
+
69
69
  UIImage *image;
70
70
  NSURL *imageURL = [RCTConvert NSURL:options[@"url"]];
71
71
  if (imageURL) {
@@ -92,22 +92,45 @@
92
92
  -(void)savePictureAndOpenInstagram:(UIImage *)base64Image
93
93
  reject:(RCTPromiseRejectBlock)reject
94
94
  resolve:(RCTPromiseResolveBlock)resolve {
95
-
95
+
96
+ // Check for photo library permissions
97
+ PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
98
+ if (status == PHAuthorizationStatusNotDetermined) {
99
+ [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus newStatus) {
100
+ dispatch_async(dispatch_get_main_queue(), ^{
101
+ if (newStatus == PHAuthorizationStatusAuthorized) {
102
+ [self savePictureAndOpenInstagram:base64Image reject:reject resolve:resolve];
103
+ } else {
104
+ if (reject != NULL) {
105
+ reject(@"com.rnshare", @"Photo library access denied by user", nil);
106
+ }
107
+ }
108
+ });
109
+ }];
110
+ return;
111
+ } else if (status != PHAuthorizationStatusAuthorized) {
112
+
113
+ if (reject != NULL) {
114
+ reject(@"com.rnshare", @"Photo library access not authorized", nil);
115
+ }
116
+ return;
117
+ }
118
+
96
119
  NSURL *URL = [self fileURLWithTemporaryImageData:UIImageJPEGRepresentation(base64Image, 0.9)];
97
120
  __block PHAssetChangeRequest *_mChangeRequest = nil;
98
121
  __block PHObjectPlaceholder *placeholder;
99
-
122
+
100
123
  [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
101
-
124
+
102
125
  NSData *pngData = [NSData dataWithContentsOfURL:URL];
103
126
  UIImage *image = [UIImage imageWithData:pngData];
104
127
  _mChangeRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:image];
105
128
  placeholder = _mChangeRequest.placeholderForCreatedAsset;
106
129
  } completionHandler:^(BOOL success, NSError *error) {
107
-
130
+
108
131
  if (success) {
109
132
  NSURL *instagramURL = [NSURL URLWithString:[NSString stringWithFormat:@"instagram://library?LocalIdentifier=\%@", [placeholder localIdentifier]]];
110
-
133
+
111
134
  if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
112
135
  if (@available(iOS 10.0, *)) {
113
136
  [[UIApplication sharedApplication] openURL:instagramURL options:@{} completionHandler:NULL];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-native-share",
3
3
  "description": "Social share, sending simple data to other apps.",
4
- "version": "12.0.10",
4
+ "version": "12.0.11",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/react-native-community/react-native-share.git"